Algorithm Problems using java

  1. Given an array arr[] of N distinct integers, check if this array is Sorted and Rotated clockwise.
    A sorted array is not considered as sorted and rotated, i.e., there should be at least one rotation.

Note:-Array can be sorted both increasingly and decreasingly

Input

The first line of input contains number of testcases T. Each testcase contains 2 lines, the first line contains N, the number of elements in array, and second line contains N space separated elements of array.

Constraints:
1 <= T <= 50
3 <= N <= 10^3
1 <= A[i] <= 10^4

Output

Print “Yes” if the given array is sorted and rotated, else Print “No”, without Inverted commas.

Example

Sample Input:
2
4
3 4 1 2
3
1 3 2

Sample Output:
Yes
Yes

  1. Given an integer K, find a positive integer x such that K = x2 + 3*x. If no such positive integer x exists, print -1.

Input

First and the only line of the input contains an integer K.

Constraints:
1 <= K <= 1018

Output

Print a positive integer x such that the above equation satisfies. If no such integer x exists, print -1.

1 Like

For some questions I am not able to build logic or I fail to get the proper way to solve them.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.