## sandeepmnit35

BAN USER- 0of 0 votes

AnswersThere are N trees growing along the street. For safety reasons, one if the trees needs to be cut down. The local council wants the street to looks ordered, so all the remaining trees needs to be in non-decreasing order of height. Your goal is to count number of ways this can be done.

- sandeepmnit35 in India

Write a function

class Solution { public int solution (int[] A); }

Each element in the tree denote the height of tree.

return 0 If this condition can't be satisfied.

Example :

Given A[3,4,5,4] Your function should return 2. You can cut down the tree of height 5 and second tree of height 4.

Given A[4,5,2,3,4] Should return 0 as after cutting any tree , it can't be ordered by height.

Given A[1,2,3....100000] Should return 100000. You can cut any one tree.| Report Duplicate | Flag | PURGE

Applications Developer Algorithm - 0of 0 votes

AnswerYou have been given a string and a number. You need to find the longest common suffix between string and substring(0 to number)

- sandeepmnit35 in United States

Example : String = "ababa"

Number is 3

Take a substring from 0 to 2 which is aba

now find the longest matching suffix between "ababa" and "aba"| Report Duplicate | Flag | PURGE

Computer Scientist Algorithm - 0of 0 votes

AnswersYou have a non empty binary array with value 0 and 1. You can flip either 0 or 1 bit of array to make the consecutive element same.You have to return the count of consecutive number with same digit.

Input : [ 1,0,1,0,0,0]

Output : 4

if you flip the value of 1st index to 1, you have 2 consecutive 1 and 2 consecutive 0 so total 4.

input : [0,0,0,0]

output : 3

input : [0]

output 1

there is bug in below code which i couldn't find it.

- sandeepmnit35 in India`class Solution { int solution(int[] A) { int n = A.length; int result = 0; for (int i = 0; i < n - 1; i++) { if (A[i] == A[i + 1]) result = result + 1; } int r = 0; for (int i = 0; i < n; i++) { int count = 0; if (i > 0) { if (A[i - 1] != A[i]) count = count + 1; else count = count - 1; } if (i < n - 1) { if (A[i + 1] != A[i]) count = count + 1; else count = count - 1; } r = Math.max(r, count); } return result + r; } }`

| Report Duplicate | Flag | PURGE

Amdocs Android Engineer Arrays - 3of 3 votes

AnswersYou have given height array of array. Generate the original array.

- sandeepmnit35 in India

Input: [6,3,0,2,2,0,0]

Output : [ 1,5,7,3,2,6,4]

A[i] value in input array is the number of greater element on right side.| Report Duplicate | Flag | PURGE

Goldman Sachs Developer Program Engineer Algorithm - 0of 0 votes

AnswersHow to print nested array ?

- sandeepmnit35 in India

Input : [1, 5, 8, [9, 10, 24, 20, [39, 48], 89], 105, 99]

Output : 1, 5, 8, 9, 10, 24, 20, 39, 48, 89, 105, 99.

Which data structure you will use to store the values?| Report Duplicate | Flag | PURGE

Goldman Sachs Developer Program Engineer Algorithm - 0of 0 votes

AnswersJacob and Peter have their favorite number X and Y. We have given an array with positive interger number and we need to find the longest prefix index which contain equal number of X and Y. return -1 if there is no prefix with equal number of X and Y.

Suppose we have an array A = [7,42,5,6,42,8,7,5,3,6,7]

X = 7

Y =42

Output should be 9 as prefix will be index from 0 to 9 with equal number of X and Y.

I wrote below code but this has some bug which I could not find.

- sandeepmnit35 in India`public int findIndex(int A[],int N,int X,int Y) { int nx =0; int ny=0; int result = -1; for( int i=0;i<N;i++) { if(A[i] == X) nx+=1; else if(A[i] == Y) ny+=1; if(nx== ny&& nx!=0&&ny!=0) result = i; } return result; }`

| Report Duplicate | Flag | PURGE

Groupon Applications Developer Algorithm

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

Initiate random number with value 0 to n. get a number from this function and then swap this number with last number of array. then call the random fucntion with 0 to n-1... and swap the number with n-1 index and repeat the process.

- sandeepmnit35 July 10, 2018