Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You and your friends are solving a puzzle called the cross - number puzzle. Here the task is to reach the destination by spending a

You and your friends are solving a puzzle called the cross-number puzzle. Here the task is to reach the destination by spending a minimum number of coins. You are placed initially at zero, here at th step you can move I steps either to the left or right by spending i coins. Return the minimum number of coins you need to spend to reach the destination.
Function description
Complete the solve() function. This function takes the following argument and returns 1 if the string word is valid else return 0:
N. Represents the target
Input format for custom testing
Note: Use this input format if you are testing against custom input or writing code in a language where we don't provide boilerplate code
The first line contains an integer N denoting the target.
Output format
Print the total cost to reach the destination.
Constraints
-10< N <109
Sample input
4
Sample output
6
Explanation
Initial cost-0
1. Move from O by 1 step to the left to 1. Cost-0-1-1
2. Move from-1 by 2 steps to the right to 1. Cost-1+2-3
3. Move from 1 by 3 steps to the right to 4. Cost =3+3-6
Therefore, retum 6.
Note:
Your code must be able to print the sample output from the provided sample input. However, your code is run against multiple hidden test cases. Therefore, your code must pass these hidden test cases to solve the problem statement.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions