Coding Ninja Interview Experience



A train130 meters long travels at a speed of 45 km/hr crosses a bridge in 30 seconds. The length of the bridge is:

270 m

235 m

245 m

220 m

A total of 250 players participated in a single tennis knock out tournament. What is the total number of matches played in the tournament? (Knockout means if a player loses, he is out of the tournament). No match ends in a tie.





The Pokemon Republic has some very strange customs. Couples only wish to have female children as only females can inherit the family’s wealth, so if they have a male child they keep having more children until they have a girl. If they have a girl, they stop having children. What is the ratio of girls to boys in Pokemon Republic?





If the probability that Stock A will increase in value during the next month is 0.54, and the probability that Stock B will increase in value during the next month is 0.68. What is the greatest value for the probability that neither of these two events will occur?





There is a circular jail with 100 cells numbered from 1 to 100. One night the jailor gets drunk and starts running around the jail in circles. In his first round he opens every door. In his second round he visits every 2nd door (2,4,6,…) and shuts the door. In the 3rd round he visits every 3rd door (3,6,9,…) and if the door is shut he opens it, if it is open he shuts it. This process of crazy drunken-ness continues for 100 rounds and finally the jailor gets exhausted and falls down. Let us assume the prisoners are all kind enough to wait until the crazy jailor stops and finally they decide to escape. By the end of all this, how many prisoners find their doors open?





What is the output of following C program?

#include <stdio.h>

int main()
   int *ptr, a = 10;
   ptr = &a;
   *ptr += 1;
   printf(“%d,%d/n”, *ptr, a);





What is the output of following program?

#include <stdio.h>

void foo( int[] );
int main()
   int ary[4] = {1, 2, 3, 4};
   printf(“%d “, ary[0]);
void foo(int p[4])
   int i = 10;
   p = &i;
   printf(“%d “, p[0]);

10 10

Undefined Behaviour

Compile Time Error

10 1

What is the time complexity of following code?





None of These

What is the time complexity for the following function?

void fun2(int m, int n = 1)
 if (n <= 0)
 if (n > m)
 fun2(m, 2*n);





Which of the following is FALSE about references in C++?

References cannot be NULL

A reference must be initialized when declared

Once a reference is created, it cannot be later made to reference another object; it cannot be reset.

References cannot refer to constant value


Without using any addition LL arrange elements in a LL such that all even numbers are placed after odd numbers, relative order of even and odd shouldn’t change .

Input Format : Input contains multiple numbers each with separated by a space except last ,representing each node of linked list with -1 stating as end or NULL.

Output Format: Print the output LL, each element should be separated by a space and LL end should be shown by a -1

Sample test case : 1 2 3 4 -1

Output: 1 3 2 4 -1

Function Signature: ListNode & Node classes are defined for you in the sample file.

CPP: ListNode* oddEvenList(ListNode* head);

Java: public static Node<Integer> evenAfterOdd(Node<Integer> head);

Find equilibrium index of an array. Equilibrium index of an array is an index such that the sum of elements at lower indexes is equal to the sum of elements at higher indexes.

Input format: Input contains size of the array followed by the array

Output format: Print the obtained index

Sample Test:



-7 1 5 2 -4 3 0



(implies that a[0]+a[1]+a[2] = a[4]+a[5]+a[6])

Function Signature:

CPP: int equilibrium_Index(vector<int> &ar); Java: private static int getEquilibriumIndex(int[] input);

Given a integer h, find the possible number of balanced binary trees of height h. This number can be huge, so return output modulus 10^9 + 7.

Sample Input: 3

Sample Output: 15

You need to write a function with following signature.

C++: int BTreeOfGivenHeight(int Required_height);

Java: public static int balancedTreesOfHeight(int height);




    1. Given a string s, generate all the possible substrings of s. E.g. if s  = “abc” output should be {“”, a, b, c, ab, bc, abc}
    2. Given a string s, find the length of maximum possible palindrome that can be generated from s.
    3. Given a Binary Tree, Count the number of nodes.
    4. Given a Binary tree, print all nodes that does not have their siblings.
    5. Given a Binary Tree, print all leaf nodes.


    1. Explain your best project.
    2. What motivated you to join Coding Ninjas.
    3. Where do you see yourself in five years.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.