## Recent Interview Questions

More Questions »- 0of 0 votes
You have a cycled doubly linked list (meaning there is a cycle and each node has prev() and next() method).

You can set/check the value of each node in the list to be 0/1 (method setValue(0/1) getValue())

Find how many elements there are in the list.

You start from the some node and you don’t know the status of the nodes value, could be any combination of 1’s and 0’s)..

- 0of 0 votes
Look at the following sequence:

3, 5, 6, 9, 10, 12, 17, 18, 20....

All the numbers in the series has exactly 2 bits set in their binary representation. Your task is simple, you have to find the Nth number of this sequence.

1 <= T <= 10^6

1 <= N <= 10^14

I tried to implement it as follows but it is giving me wrong answer for some hidden cases.`#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; #define MAX 10000 #define MOD 1000000007 long long int m[MAX+1]; long long int sum; long long int binary_search(long long int n) { long long int low=0,high=MAX,mid; while(low<high) { mid=low+(high-low+1)/2; if(m[mid]<=n) low=mid; else high=mid-1; } return low; } int main() { m[0]=1; for(long long int i=1;i<=MAX;i++) m[i]=m[i-1]+i; long long int n,k,l; int t; scanf("%d",&t); for(int test=0;test<t;test++) { scanf("%lld",&n); k=binary_search(n); //cout<<m[k]<<" "; l=n-m[k]; cout<<((1<<k+1)%MOD+(1<<l)%MOD)%MOD<<"\n"; } return 0; }`

- 0of 0 votes
Find the given doubly linked list is palindrome or not.

- 0of 0 votes
Optimization Game

Currently, Monk is playing a unique kind of strategy game called optimisation game.

In this game we are provided with an array containing integral numbers.

Now all these numbers represent the count of their respective index power of 2.

The goal of the game is to minimize the total sum of the count of the array by converting lower powers of 2 into their higher powers

i.e. for example (2)*2^1 = (1)*2^2.

Note that we can extend the array beyond the final index i.e. N−1 too in case it optimizes our result.

Please see the below example for more understanding.

Let the number of elements given in the initial array be 3. Consider the array to be [1,2,0].

It means that 2^0 has count = 1, 2^1 has count = 2, 2^2 has count = 0.

Now, we can convert (2)*2^1 into (1)*2^2 as 2^1∗2 = 2^2. We get the new array as [1,0,1].

Now the total sum is 1+0+1=2 which is the required minimum value obtained at the end of the game as we can't reduce it any further.

Input:

First line will contain the number of test cases as T.

For each of the test case, N will be given in the first line and N integers will be given in the second line.

Output:

Output the minimum value obtained after playing the optimization game in a separate line for each test case.

Constraint:

1≤T≤5

1≤N≤10^5

0≤A[i]≤2∗10^9

Sample Input

2

3

1 2 1

2

2 1

Sample Output

2

1

Explanation

In the second case we have A[0]=2, A[1]=1. We can convert A[0] into A[1] and then finally (1+1=2) A[1] into A[2]. Thus, the final array shall be : [0,0,1]. Hence, the answer is 1.

- 0of 0 votes
On google search, how to enable key word auto completion after a few letters typed.

Follow-up: How to rank the words if they are weighted by frequency?