## sarunreddy82

- 0of 0 votes

Answers# Given a set of strings, print them in Lexicographic order (dictionary/alphabetical order)

- sarunreddy82 in United States

# Example,

# Input:

# “ABCDEF”, “AA”, “BEF”, “A”, “AABB”

# Output:

# “A”, “AA”, “AABB”, “ABCDEF”, “BEF”| Report Duplicate | Flag

VMWare Inc String Manipulation - 0of 0 votes

AnswersDesign a music streaming service like Pandora.

- sarunreddy82 in United States| Report Duplicate | Flag

Amazon System Design - 1of 1 vote

AnswersGiven a number, rearrange the digits of that number to make a higher number, among all such permutations that are greater,one of them is the smallest, Find the smallest greater permutation (the next Permutation).

- sarunreddy82 in United States

Examples:

next_permutation (12) = 21

next_permutation (315) = 351

next_permutation (583) = 835

next_permutation (12389) = 12398

next_permutation (34722641) = 34724126| Report Duplicate | Flag

Facebook Java - 0of 0 votes

AnswersFirst common Ancestor of Binary tree . Java Solution needed.

- sarunreddy82 in United States

Class Node {

Node Parent;

Node LeftChild;

Node rightChild;

int val;

}

publlic Node firstAncestor(Node leftNode, Node rightNode){

// We don't get the root node here. From left and right child we need to find it's parent and find the lowest common ancestor.

}| Report Duplicate | Flag

xyz Trees and Graphs - 0of 0 votes

AnswersProblem:

- sarunreddy82 in United States

Insert + or – sign anywhere between the digits 123456789 in such a way that the expression evaluates to 100. The condition is that the order of the digits must not be changed.

e.g.: 1 + 2 + 3 – 4 + 5 + 6 + 78 + 9 = 100

I have below C solution - Can you please help me to convert to Java. I need this solution in Java.

#include<stdio.h>

#include<conio.h>

int findnumber(int i,int j)

{

int k;

int n;

for(k = 0; k < j; k++)

{

n = i % 3;

i = i / 3;

}

return n;

}

void main()

{

int i, j, k, current, result, operation;

clrscr();

for(i = 0; i < 19683; i++)

{

if(i%3 == 0)

continue;

current = 0;

result = 0;

for(j = 1; j < 10; j++)

{

k = findnumber(i,j);

if(k==0)

{

current = current * 10 + j;

}

else

{

result = result + (operation == 1 ? current : -current);

current = j;

operation = k;

}

}

result = result + (operation == 1 ? current : -current);

if(result == 100)

{

for(j = 1; j < 10; j++)

{

k = findnumber(i,j);

if(k==0)

printf("%d",j);

else

printf("%c%d",k==1?'+':'-',j);

}

printf("\n");

}

}

getch();

}| Report Duplicate | Flag

xyz Java - 0of 0 votes

AnswersLanguage : java

- sarunreddy82 in United States

Find the length of the non repeated numbers in an array.

Input : 1,2,2,3,4,5,6,2,3| Report Duplicate | Flag

xyz abc Arrays - 0of 0 votes

AnswersGiven an array of n strings, sentences, where each sentences, consists of most w space-separated words, we want to perform q queries given by an array of q strings named queries where each queries consists of at most k space-separated words. To answer query queriesj, we find all the indices in sentences that contain every word in queries and assemble them into an array of indices listed in ascending order. For example, if all the words in queries are only found in sentences4, sentences9 and sentences2 , then the answer to queriesj is the array[2,4,9].

- sarunreddy82 in United States

Input Format:

The first line contains an integer, n, denoting the number of Strings in sentences

Each line i of the n subsequent lines contains at most w space-separated words describing sentences

The next line contains an integer, q, denoting the number of strings in queries

Each line j of the q subsequent lines contains at most k space-separated words describing queries.

1) Sample I/P format:

3

jim likes mary

kate likes tom

tom does not like jim

2

jim tom

likes

O/P:

2

0 1

2) Sample I/P Format:

4

how it was done

are you how

it goes to it

goes done are it

2

done it

it

O/P:

0 3

0 2 2 3

Note: Solution in Java only

static void searchQueries(String[] sentences, String[] queries) {

}| Report Duplicate | Flag

xyz Arrays - 0of 0 votes

AnswersLanguage : Java

- sarunreddy82 in United States

Given a binary tree, print boundary nodes of the binary tree counter-clockwise starting from the root.

For example, boundary traversal of the following tree is “20 8 4 10 14 25 22”

20

8 22

4 12 25

10 14| Report Duplicate | Flag

xyz Algorithm - 0of 0 votes

AnswerDesign a system to support a pool of servers. The pool Api should be able to add a server, get a server (can be random) and delete a server from the pool.

- sarunreddy82 in United States

You need to design and implement an interface for such pool.

The pool implementation should operate with a high performance so all operations need to be done in O(1).| Report Duplicate | Flag

xyz - 0of 0 votes

AnswersGiven the N*N matrix, find the given number in the matrix. All rows are sorted. And each row first element is less than the previous row last index.

- sarunreddy82 in United States

input :

[1,3,5,7,9]

[11,13,15,16,20]

[21,22,23,24,25]

[30,32,35,40,45]

Given Num : 23

What is the best Optimal solution ? I have used BST but the interviewer asked to use any other which could do better in the above scenario.| Report Duplicate | Flag

xyz Developer Program Engineer Matrix - 0of 0 votes

AnswerGiven the below input and ouput.

- sarunreddy82 in United States

Input :

String[] input = {"hello", "world"};

output: (Higher count should come before and natural order)

hello : l=2, e=1,h=1,o=1

world: d=1,l=1,o=1,r=1,w=1| Report Duplicate | Flag

xyz None Arrays - 0of 0 votes

AnswersGiven the below input and output and asked to write in Java.

- sarunreddy82 in United States

Example 1)

input : {1,2,3,4, &, 12,13,14,15}

output : {15,14,13,12,1,2,3,4}

Example 2 )

input : {33,34,&,55,63}

output : {63,55,33,34}

Assumption : '&' will always be in the middle.| Report Duplicate | Flag

xyz Backend Developer Arrays

private static void findNextPermutation(char[] numArr) {

if(numArr.length == 0) {

return;

}

// Find the max i, so that K(i-1) < ki

// Find the max j, so that K(i-1) < kj

// Swap Ki and K(i-1)

// reverse from Ki, ki+1.... kn;

int i = numArr.length -2;

while(i >=0 && numArr[i+1] <= numArr[i]) {

i--;

}

if(i >=0) {

int j = numArr.length -1;

while(j >=0 && numArr[j] <= numArr[i]) {

j--;

}

swap(numArr, i, j);

}

reverse(numArr, i+1);

for(char c : numArr) {

System.out.print(c + ", ");

}

}

private static void reverse(char[] numArr, int start) {

int i = start; int j = numArr.length -1;

while(i <j) {

swap(numArr,i,j);

i++;

j--;

}

}

private static void swap(char[] numArr, int i, int j) {

char temp = numArr[i];

numArr[i] = numArr[j];

numArr[j] = temp;

}

Looks like your method will take int array. But in the above problem it says int number. How does it work ?

- sarunreddy82 May 15, 2018Thanks Denis. Do you have java solution as well ?

- sarunreddy82 February 23, 2018**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

Can anyone one help me solve this using Trie DS. I have given all the above solutions but interviewer asked me to implement using Trie.

- sarunreddy82 July 15, 2018