sandeepmnit35
BAN USER
- 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 Indiaclass 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 - 4of 4 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 Indiapublic 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
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