├── 2nd.docx ├── Test Your C Skills.pdf ├── zoho 2nd round questions └── zoho 3rd round /2nd.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeologic/zoho-round/945110326010af8e5033152de477b7d56a008153/2nd.docx -------------------------------------------------------------------------------- /Test Your C Skills.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeologic/zoho-round/945110326010af8e5033152de477b7d56a008153/Test Your C Skills.pdf -------------------------------------------------------------------------------- /zoho 2nd round questions: -------------------------------------------------------------------------------- 1 | 1. Replace every element with the greatest element on right side 2 | Last Updated: 06-05-2019 3 | Given an array of integers, replace every element with the next greatest element (greatest element on the right side) in the array. Since there is no element next to the last element, replace it with -1. For example, if the array is {16, 17, 4, 3, 5, 2}, then it should be modified to {17, 5, 5, 5, 2, -1}. 4 | 2. Given a Boolean matrix mat[M][N] of size M X N, modify it such that if a matrix cell mat[i][j] is 1 then make its adjacent cells as 0. 5 | 3. 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. For example, in an array A: 6 | Example : 7 | Input: A[] = {-7, 1, 5, 2, -4, 3, 0} 8 | Output: 3 9 | 3 is an equilibrium index, because: 10 | A[0] + A[1] + A[2] = A[4] + A[5] + A[6] 11 | Input: A[] = {1, 2, 3} 12 | Output: -1 13 | 4. In MS-Paint, when we take the brush to a pixel and click, the color of the region of that pixel is replaced with a new selected color. Following is the problem statement to do this task. 14 | Given a 2D screen, location of a pixel in the screen and a color, replace color of the given pixel and all adjacent same colored pixels with the given color. 15 | Example: 16 | Input: 17 | screen[M][N] = {{1, 1, 1, 1, 1, 1, 1, 1}, 18 | {1, 1, 1, 1, 1, 1, 0, 0}, 19 | {1, 0, 0, 1, 1, 0, 1, 1}, 20 | {1, 2, 2, 2, 2, 0, 1, 0}, 21 | {1, 1, 1, 2, 2, 0, 1, 0}, 22 | {1, 1, 1, 2, 2, 2, 2, 0}, 23 | {1, 1, 1, 1, 1, 2, 1, 1}, 24 | {1, 1, 1, 1, 1, 2, 2, 1}, 25 | }; 26 | x = 4, y = 4, newColor = 3 27 | The values in the given 2D screen indicate colors of the pixels. 28 | x and y are coordinates of the brush, newColor is the color that 29 | should replace the previous color on screen[x][y] and all surrounding 30 | pixels with same color. 31 | 32 | Output: 33 | Screen should be changed to following. 34 | screen[M][N] = {{1, 1, 1, 1, 1, 1, 1, 1}, 35 | {1, 1, 1, 1, 1, 1, 0, 0}, 36 | {1, 0, 0, 1, 1, 0, 1, 1}, 37 | {1, 3, 3, 3, 3, 0, 1, 0}, 38 | {1, 1, 1, 3, 3, 0, 1, 0}, 39 | {1, 1, 1, 3, 3, 3, 3, 0}, 40 | {1, 1, 1, 1, 1, 3, 1, 1}, 41 | {1, 1, 1, 1, 1, 3, 3, 1}, 42 | }; 43 | 5. Given a matrix of 2D array of n rows and m coloumns. Print this matrix in ZIG-ZAG fashion as shown in figure. 44 | 45 | Example: 46 | Input: 47 | 1 2 3 48 | 4 5 6 49 | 7 8 9 50 | Output: 51 | 1 2 4 7 5 3 6 8 9 52 | 6. Remove the duplicates in the String. 53 | Testcase 1: 54 | Input: Java1234 55 | Output: Javb1234 (Remove the second ‘a’ as it is duplicated) 56 | Testcase 2: 57 | Input: Python1223: 58 | Output: Python1234 (Replace the second 2 with 3, and replace 3 with 4 as 3 is replaced for the duplicated 2) 59 | Testcase 3: 60 | Input: aBuzZ9900 61 | Output: aBuzC9012 62 | (Replace the second ‘Z’ with ‘C’ as ‘a’ and ‘B’ are already there in the String. Replace with capital C as the letter to be replaced is capital Z. The second 9 turns out to be zero and the zero turns out to ‘1’ and the second zero turns out to ‘2’) 63 | 7. Print whether the version is upgraded, downgraded or not changed according to the input given. 64 | example: Input : Version1 4.8.2 Version2 4.8.4 Output: upgraded, Input : Version1 4.0.2 Version2 4.8.4 Output: downgraded 65 | 8. Q2. Print all possible subsets of the given array whose sum equal to given N. 66 | example: Input: {1, 2, 3, 4, 5} N=6 Output: {1, 2, 3}, {1, 5}, {2, 4} 67 | 9. Reverse the words in the given String1 from the first occurrence of String2 in String1 by maintaining white Spaces. 68 | example: String1 = Input: This is a test String only String2 = st Output: This is a only String test 69 | 10. calculate Maximum number of chocolates can eat and Number of wrappers left in hand. 70 | Money: Total money one has to spend. 71 | Price: price per chocolate. 72 | wrappers: minimum number of wrappers for exchange choco: number of chocolate for wrappers. 73 | Max visit: Maximum number of times one can visit the shop.(if zero consider it infinite) 74 | example: input: Money:40 Price:1 wrappers:3 choco:1 Max visit:1 Output: total chocolate can eat: 53 wrappers left in hand:14 75 | 11. 76 | Sample Input- 77 | 2 78 | Hacker 79 | Rank 80 | Sample Output- 81 | Hce akr 82 | Rn ak 83 | 2. 84 | Sample Input- 85 | 13.Print the word with odd letters – PROGRAM 86 | Sample Output- 87 | P P 88 | R R 89 | O O 90 | G 91 | R R 92 | A A 93 | M M 94 | 14. 95 | Sample Input – Alternate Sorting 96 | 97 | 98 | Input: {1, 2, 3, 4, 5, 6, 7} 99 | output: {7, 1, 6, 2, 5, 3, 4} 100 | 101 | 15.Given an array of values persons[], each represents the weight of the persons. There will be infinite bikes available. Given a value K which represents the maximum weight that a bike accommodates. Along with that one more condition, a bike can carry two persons at a time. You need to find out the least number of times, the bike trips are made. 102 | 16.Assume there exists infinite grid, you’re given initial position x, y. Inputs will be movements either L or R or U or D. After n inputs, you need to give the current position. 103 | • Input: 104 | • 4 5 //initial position x, y 105 | • 9 //number of movements 106 | • U L R R D D U L R //7 movements 107 | • Output: 108 | 5 5 109 | • Given a matrix NxN, you are initially in the 0, 0 position. The matrix is filled with ones and zeros. Value “one” represents the path is available, while “zero” represents the wall. You need to find the can you able to reach the (N-1)x(N-1) index in the matrix. You can move only along the right and down directions if there’s “one” available. 110 | • Input: 111 | • 5 //N value 112 | • 1 0 1 0 0 113 | • 1 1 1 1 1 114 | • 0 0 0 1 0 115 | • 1 0 1 1 1 116 | • 0 1 1 0 1 117 | • Output: 118 | Yes 119 | 17.Given an array of integers, compute the maximum value for each integer in the index, by either summing all the digits or multiplying all the digits. (Choose which operation gives the maximum value) 120 | • Input: 121 | • 5 122 | • 120 24 71 10 59 123 | • Output: 124 | • 3 8 8 1 45 125 | Explanation: For index 0, the integer is 120. Summing the digits will give 3, and whereas Multiplying the digits gives 0. Thus, maximum of this two is 3. 126 | . 18. -1 represents ocean and 1 represents land find the number of islands in the given matrix. 127 | 128 | 129 | 130 | Input: n*n matrix 131 | 1 -1 -1 1 132 | -1 1 -1 1 133 | -1 -1 1 -1 134 | -1 -1 -1 1 135 | Output: 2 (two islands that I have 136 | bold in matrix at 1, 1 and 2, 2) 137 | 19. Print all the possible subsets of array which adds up to give a sum. 138 | Input: array{2, 3, 5, 8, 10} 139 | sum=10 140 | Output: {2, 3, 5} 141 | {2, 8} 142 | {10} 143 | 20. There is a circular queue of processes. Every time there will be certain no of process skipped and a particular start position. Find the safe position. 144 | Input: Number of process:5 145 | Start position:3 146 | Skip: 2nd 147 | Output: 1 will be the safest position 148 | (Logic: 1 2 3 4 5 starting from 3, 5th process will be skipped 149 | 1 2 3 4 5 process 2 will be skipped 150 | 1 2 3 4 5 process 4 will be skipped 151 | 1 2 3 4 5 process 3 will be skipped, so safest process is 1. 152 | 153 | 154 | . 155 | 21.Given N. print the following snake pattern (say N = 4). condition: must not use arrays ( 1D array or 2D array like Matrix ). 156 | 1 2 3 4 157 | 8 7 6 5 158 | 9 10 11 12 159 | 16 15 14 13 160 | 161 | 22.Given N. print the Latin Matrix (say N = 3). condition: must not use strings(aka character literals), arrays (both 1D and 2D), inbuilt functions(like rotate). 162 | 163 | 164 | 165 | A B C 166 | B C A 167 | C A B 168 | 23. Given a number N. find the minimum count of numbers in which N can be represented as a sum of numbers x1, x2, … xn. where xi is number whose digits are 0s and 1s. 169 | example 1) i/p : N = 33 170 | o/p : count = 3. 33( 11 + 11 + 11 ) 171 | some other possibilities of 33 is (11 + 11 + 10 + 1), (11 + 10 + 10 + 1 + 1 ), (10 + 10 + 10 + 1 + 1 + 1) 172 | 24. Finding all permutations of a string. ( backtracking approach ). 173 | 25. Given an array of integers, write a program to re-arrange the array in the given form. 174 | 1st_largest, 1st_smallest, 2nd_largest, 2nd_smallest, 3rd_largest ……. etc. 175 | 26.Sort the given elements in decending order based on the number of factors of each element – Solution 1 176 | 27.Find whether the given number is palindrome or not. Don’t use arrays or strings 177 | 28.Reverse the given string keeping the position of special characters intact 178 | 29.Find the shortest path from one element to another element in a matrix using right and down moves alone. The attached solution uses moves in all directions. – Solution 4 179 | 30.Pattern 180 | 31. 1. Pangram Checking 181 | Check whether all english alphabets are present in the given sentence or not 182 | I/P: abc defGhi JklmnOP QRStuv wxyz 183 | O/P: True 184 | I/P: abc defGhi JklmnOP QRStuv 185 | O/P: False 186 | 32. Password Strength 187 | Find the strength of the given password string based on the conditions 188 | Four rules were given based on the type and no. of characters in the string. 189 | Weak – only Rule 1 is satisfied or Rule 1 is not satisfied 190 | Medium – Two rules are satisfied 191 | Good – Three rules satisfied 192 | Strong – All Four rules satisfied 193 | 194 | 195 | 196 | I/P: Qw!1 O/P: Weak 197 | I/P: Qwertyuiop O/P: Medium 198 | I/P: QwertY123 O/P: Good 199 | I/P: Qwerty@123 O/P: Strong 200 | 33. First Occurrences 201 | Given two strings, find the first occurrence of all characters of second string in the first string and 202 | print the characters between the least and the highest index 203 | I/P: ZOHOCORPORATION PORT 204 | O/P: OHOCORPORAT 205 | Explanation: The index of P in first string is 7, O is 1, R is 6 and T is 11. The largest range is 1 – 11. 206 | So print the characters of the first string in this inex range i.e. OHOCORPORAT 207 | 34. Matrix Diagonal sum 208 | Given a matrix print the largest of the sums of the two triangles split by diagonal from top right to bottom left 209 | I/P: 210 | 3 3 211 | 1 2 3 212 | 4 5 6 213 | 7 8 9 214 | O/P: 38 215 | 35. Matrix Addition 216 | Given n integer arrays of different size, find the addititon of numbers represented by the arrays 217 | I/P: 4 218 | 3 5 4 2 219 | 2 4 5 220 | 4 5 6 7 8 221 | 4 9 2 1 222 | 1 2 223 | O/P: 50856 224 | Problem 36: 225 | Many students will able to solve 3 problems in this round. So make sure you stand apart from the crowd.Their vacancy is going to be 5 for a team. The performance in this round could be taken as a tie breaker for round 3. 226 | input : aaabbcc 227 | output : abc 228 | Problem 37.: 229 | Evaluate the expression and sort and print the output. Getting the input is the tricky part 230 | Input: 231 | Number of input : 4 232 | 2*3 233 | 2^2^2 234 | 35 235 | 3*1 236 | Output: 237 | 3*1 238 | 2*3 239 | 2^2^2 240 | 35 241 | Problem 38: 242 | 243 | 244 | 245 | Given a 6 blocks, of different height h1, …, h6 . Make 2 towers using 3 Blocks for each tower in desired height h1, h2. Print the blocks to be used in ascending order 246 | Input: 247 | 1 2 5 4 3 6 248 | height of tower: 6 15 249 | Output : 250 | 1 2 3 & 4 5 6 251 | Problem 39: 252 | Given a 5X5 chess board as input. 9 knights are placed in the board. Print whether the configuration valid or Invalid. 253 | Problem 40: 254 | Given a number, print all the code that can be formed with z={a=1, .., z=26}. 255 | 256 | 257 | 258 | 1123 259 | {1, 1, 2, 3} = aabc 260 | {11, 2, 3} = kbc 261 | {1, 1, 23} = aaw 262 | {11, 23} = kw 263 | 41.Given a String with or without special characters find if it is Palindrome or Not.. No splitting of array must be done or No additional spaces must be used for storing the array.. 264 | Eg: RACE CAR 265 | Eg: I DID, DID I ? 266 | 267 | 268 | 42. Given an array of integers of size n. Convert the array in such a way that if next valid number is same as current number, double its value and replace the next number with 0. After the modification, rearrange the array such that all 0’s are shifted to the end. 269 | Input : arr[] = {2, 2, 0, 4, 0, 8} 270 | Output : 4 4 8 0 0 0 271 | Input : arr[] = {0, 2, 2, 2, 0, 6, 6, 0, 0, 8} 272 | Output : 4 2 12 8 0 0 0 0 0 0 273 | 43 . TWISTED PRIME NUMBER 274 | A number is said to be twisted prime if it is a prime number and reverse of the number is also a prime number. 275 | Input : 97 276 | Output : Twisted Prime Number 277 | Explanation: 97 is a prime number 278 | and its reverse 79 is also a prime 279 | number. 280 | 44.Given an array A[] and a number x, check for pair in A[] with sum as x. 281 | Eg : Input {1, 2, 4, 3, 5, 6} 282 | SUM : 5 283 | Output : 2 (1, 4) & (2, 3) 284 | 45.Largest Sum Contiguous Subarray 285 | (Kadane’ Algorithm ) 286 | 46.Diamond pattern : for given input size -> Here 3 287 | * 288 | *** 289 | ***** 290 | *** 291 | * 292 | 293 | 294 | 46. Given a text and a wildcard pattern, implement wildcard pattern matching algorithm that finds if wildcard pattern is matched with text. The matching should cover the entire text (not partial text). 295 | The wildcard pattern can include the characters ‘?’ and ‘*’ 296 | ‘?’ – matches any single character 297 | ‘*’ – Matches any sequence of characters (including the empty sequence) 298 | Example: 299 | Text = “baaabab”, 300 | Pattern = “*****ba*****ab”, 301 | output : true 302 | Pattern = “baaa?ab”, output : true 303 | Pattern = “ba*a?”, output : true 304 | Pattern = “a*ab”, output : false 305 | 306 | 307 | 308 | 47. Given an input string and a dictionary of words, find out if the input string can be segmented into a space-separated sequence of dictionary words. See following examples for more details. 309 | Consider the following dictionary 310 | { i, like, sam, sung, samsung, mobile, ice, 311 | cream, icecream, man, go, mango} 312 | 313 | Input: ilike 314 | Output: Yes 315 | The string can be segmented as "i like". 316 | 317 | Input: ilikesamsung 318 | Output: Yes 319 | The string can be segmented as "i like samsung" 320 | or "i like sam sung".<> 321 | 48.Print the following pattern 322 | 1 323 | 3 2 324 | 6 5 4 325 | 10 9 8 7 326 | 10 9 8 7 327 | 6 5 4 328 | 3 2 329 | 1 330 | 49.Given an array as input, The condition is if the number is repeated you must add the number and put the next index value to 0. If the number is 0 print it at the last. 331 | Eg: arr[] = { 0, 2, 2, 2, 0, 6, 6, 0, 8} 332 | Output: 4 2 12 8 0 0 0 0 0 . 333 | 49. Given two Strings s1 and s2, remove all the characters from s1 which is present in s2. 334 | Input: s1=”expErIence”, s2=”En” 335 | output: s1=”exprIece” 336 | 50.Find the next greater element for each element in given array. 337 | input: array[]={6, 3, 9, 10, 8, 2, 1, 15, 7}; 338 | output: {7, 5, 10, 15, 9, 3, 2, _, 8} 339 | If we are solving this question using sorting, we need to use any O(nlogn) sorting algorithm. 340 | 51.Print all distinct permutations of a given string with duplicate characters. 341 | https://www.geeksforgeeks.org/distinct-permutations-string-set-2 342 | 52.Given a number, find the next smallest palindrome. 343 | 53.Given an array with repeated numbers, Find the top three repeated numbers. 344 | input: array[]={3, 4, 2, 3, 16, 3, 15, 16, 15, 15, 16, 2, 3} 345 | output: 3, 16, 15 346 | 54.Given two dimensional matrix of integer and print the rectangle can be formed using given indices and also find the sum of the elements in the rectangle 347 | Input: mat[M][N] = {{1, 2, 3, 4, 6}, {5, 3, 8, 1, 2}, {4, 6, 7, 5, 5}, {2, 4, 8, 9, 4} }; 348 | index = (2, 0) and (3, 4) 349 | Output: 350 | Rectangle 351 | 4 6 7 5 5 352 | 2 4 8 9 4 353 | sum 54 354 | 355 | 356 | 357 | 358 | 55. Find the result subtraction, multiplication, division of two integers using + operator. 359 | Input: 6 and 4 360 | output: 361 | addition 6+4 = 10, subtraction 6+(-4) = 2, multiplication = 24, division = 1 362 | Input : -8 and -4 363 | Output: 364 | addition -8+(-4) = -12, subtraction (-8)+(-(-4)) = -4, multiplication = 32, division = 2 365 | 366 | 56..Given a sentence of string, in that remove the palindrome words and print the remaining. 367 | Input: 368 | He did a good deed 369 | Output: 370 | He good 371 | Input: 372 | Hari speaks malayalam 373 | Output: 374 | Hari speaks 375 | 376 | 57..Given two dates, find total number of days between them. 377 | 378 | 379 | 380 | Input: dt1 = {10, 2, 2014} dt2 = {10, 3, 2015} 381 | Output: 393 382 | dt1 represents “10-Feb-2014” and dt2 represents “10-Mar-2015” The difference is 365 + 28 383 | Input: dt1 = {10, 2, 2000} dt2 = {10, 3, 2000} 384 | Output: 29 385 | Note that 2000 is a leap year 386 | Input: dt1 = {10, 2, 2000} dt2 = {10, 2, 2000} 387 | Output: 0 388 | Both dates are same 389 | Input: dt1 = {1, 2, 2000}; dt2 = {1, 2, 2004}; 390 | Output: 1461 391 | Number of days is 365*4 + 1 392 | 393 | 58. 394 | Let 1 represent ‘A’, 2 represents ‘B’, etc. Given a digit sequence, count the number of possible decodings of the given digit sequence. 395 | Examples: 396 | Input: digits[] = “121” 397 | Output: 3 // The possible decodings are “ABA”, “AU”, “LA” 398 | Input: digits[] = “1234” Output: 3 399 | // The possible decodings are “ABCD”, “LCD”, “AWD” 400 | 401 | 59.. Print all possible words from phone digits 402 | 403 | 60. Print longest sequence between same character 404 | 405 | 406 | 407 | Ex I/p abcccccbba 408 | O/p 8 (from a to a) 409 | I/p aaaaaaaa 410 | O/p 6 411 | 61..sort the array odd numbers in ascending and even numbers in descending. 412 | I/p 5 8 11 6 2 1 7 413 | O/p 1 5 7 11 8 6 2 414 | 62. It’s about anagram.i/p was array of strings .and a word was given to find whether it has anagram in given array. 415 | I/p catch, got, tiger, mat, eat, Pat, tap, tea 416 | 417 | 418 | 419 | Word: ate 420 | O/p eat, tea 421 | 63.array of numbers were given to find a number which has same sum of numbers in it’s either side. 422 | I/p 1, 2, 3, 7, 6 423 | O/p 7(has 1+ 2+3 in left 6 in right) 424 | 64.prime number – print n prime numbers 425 | 65.prime factor – sort the array based on the minimum factor they have. 426 | 66.adding a digit to all the digits of a number eg digit=4, number = 2875, o/p= 612119 427 | 67.form the largest possible number using the array of numbers. 428 | 68.lexicographic sorting. 429 | 69.given a set of numbers, and a digit in each iteration, if the digit exists in any of the numbers, remove its occurrences and ask for the next digit till the list becomes empty. 430 | 70.Check if a number ‘a’ is present in another number ‘b. 431 | 71. Find the extra element and its index 432 | Input : [ 10, 20, 30, 12, 5 ] 433 | [ 10, 5, 30, 20 ] 434 | Output : 12 is the extra element in array 1 at index 4 435 | 436 | Input : [ -1, 0, 3, 2 ] 437 | [ 3, 4, 0, -1, 2 ] 438 | Output : 4 is the extra element in array 3 at index 5 439 | 72. Find the least prime number that can be added with first array element that makes them divisible by second array elements at respective index (check for prime numbers under 1000, if exist return -1 as answer) & (Consider 1 as prime number) 440 | Input : [ 20, 7 ] 441 | [ 11, 5 ] 442 | Output : [ 1, 3 ] 443 | 444 | Explanation : 445 | (20 + ?) % 11 446 | ( 7 + ?) % 5 447 | 73. Sort the array elements in descending order according to their frequency of occurrence 448 | 449 | 450 | 451 | Input : [ 2 2 3 4 5 12 2 3 3 3 12 ] 452 | Output : 3 3 3 3 2 2 2 12 12 4 5 453 | Explanation : 3 occurred 4 times, 2 occurred 3 times, 12 occurred 2 times, 4 occurred 1 time, 5 occurred 1 time 454 | Input : [ 0 -1 2 1 0 ] 455 | Output : 0 0 -1 1 2 456 | Note : sort single occurrence elements in ascending order 457 | 74. Print true if second string is a substring of first string, else print false. 458 | Note : * symbol can replace n number of characters 459 | Input : Spoon Sp*n Output : TRUE 460 | Zoho *o*o Output : TRUE 461 | Man n* Output : FALSE 462 | Subline line Output : TRUE 463 | 464 | 465 | 75.Print second frequently occurring number in given series 466 | Example : 467 | Input: 1 1 2 3 1 2 4 468 | Output: 2 469 | Explanation: 1 occurs 3 times, 2 occurs 2 times, 3 occurs 1 time and 4 occurs 1 time. Hence second frequently occurring number in given series is 2 470 | 76.Print only numbers which is present in Fibonacci series (0 1 1 2 3 5 8 ……..) 471 | Example: 472 | 473 | 474 | 475 | Input: 2 10 4 8 476 | Output: 2 8 477 | Input: 1 10 6 8 13 21 478 | Output: 1 8 13 21 479 | 77.. Print pattern like this 480 | Example: 481 | Input: 1 482 | Output: 0 483 | 484 | Input: 2 485 | Output: 486 | 0 0 487 | 0 1 488 | 1 0 489 | 1 1 490 | 491 | Input: 3 492 | Output: 493 | 0 0 0 494 | 0 0 1 495 | 0 1 0 496 | 0 1 1 497 | 1 0 0 498 | 1 0 1 499 | 1 1 0 500 | 1 1 1 501 | 78. NxN matrix will be provided. 0->block, 1->Not a block 502 | Always starting point is (0,0), Ending point is (N-1,N-1). 503 | You have to go from starting point to ending point. One valid solution is enough. 504 | Example: 505 | 506 | Input: 507 | N=4 508 | 1 1 0 0 509 | 1 0 0 1 510 | 1 1 1 1 511 | 0 0 0 1 512 | Output: 513 | _ 1 0 0 514 | _ 0 0 1 515 | _ _ _ _ 516 | 0 0 0 _ 517 | 79.. Insert 0 after consecutive (K times) of 1 is found. 518 | Example: 519 | Input: 520 | Number of bits: 12 521 | Bits: 1 0 1 1 0 1 1 0 1 1 1 1 522 | Consecutive K: 2 523 | 524 | Output: 525 | 1 0 1 1 0 0 1 1 0 0 1 1 0 1 1 0 526 | 80.Find the maximum of three numbers? 527 | 81. Print the total number of odd and even digits in the given number. 528 | 529 | Ex. Input : 1234567 530 | 531 | Output : ODD 4 532 | EVEN 3 533 | 82. Find the second maximum among the given numbers. 534 | Ex. INPUT : 535 | 536 | Size of Array : 8 537 | Enter the elements : 2 5 1 6 2 6 7 10 538 | 539 | OUTPUT : 540 | 541 | 7 542 | 543 | Ex. INPUT : 544 | 545 | Size of Array : 4 546 | Enter the elements : 4 1 2 2 547 | 548 | OUTPUT : 549 | 550 | 2 551 | 552 | Ex. INPUT : 553 | 554 | Size of Array : 1 555 | Enter the elements : 1 556 | 557 | OUTPUT : 558 | 559 | No second maximum 560 | 83. Print the following pattern 561 | Ex. INPUT : 5 562 | 563 | OUTPUT : 564 | 565 | 1 566 | 1 1 567 | 1 2 1 568 | 1 3 3 1 569 | 1 4 6 4 1 570 | 571 | Ex. INPUT : 7 572 | 573 | OUTPUT : 574 | 575 | 1 576 | 1 1 577 | 1 2 1 578 | 1 3 3 1 579 | 1 4 6 4 1 580 | 1 5 10 10 5 1 581 | 1 6 15 20 15 6 1 582 | 84. Given a two dimensional array which consists of only 0’s and 1’s. Print the matrix without duplication. 583 | Ex. INPUT : 584 | 585 | Enter Row Size : 4 586 | Enter column size : 3 587 | Enter the matrix : 588 | 1 0 1 589 | 1 1 0 590 | 1 1 1 591 | 1 0 1 592 | 593 | OUTPUT : 594 | 595 | Unique Matrix : 596 | 1 0 1 597 | 1 1 0 598 | 1 1 1 599 | 85. Given an array of positive numbers. Print the numbers which have longest continuous range. 600 | Ex. INPUT : 601 | 602 | Enter array size : 8 603 | Enter arryay elements : 1 3 10 7 9 2 4 6 604 | 605 | OUTPUT : 606 | 607 | 1 2 3 4 608 | 609 | Ex. INPUT : 610 | 611 | Enter array size : 8 612 | Enter arryay elements : 1 3 9 7 8 2 4 6 613 | 614 | OUTPUT : 615 | 616 | 1 2 3 4 617 | 6 7 8 9 618 | 86. Given two arrays. Find its union. 619 | Input : 620 | 621 | Enter size of first array : 6 622 | Enter the elements : 1 2 3 4 5 3 623 | Enter size of second array : 4 624 | Enter the elements : 1 2 7 5 625 | 626 | OUTPUT : 627 | 628 | 1 2 3 4 5 7 629 | 8. Given an array of numbers. Print the numbers without duplication. 630 | 631 | 632 | 633 | 634 | INPUT : 635 | 636 | Enter the array size : 4 637 | Enter the elements : 1 1 2 4 638 | 639 | OUTPUT : 640 | 641 | 1 2 4 642 | 88. Given an array of numbers and a number k. Print the maximum possible k digit number which can be formed using given numbers. 643 | INPUT : 644 | 645 | Enter the array size : 4 646 | Enter the elements : 1 4 973 97 647 | Enter number of digits : 3 648 | 649 | OUTPUT : 650 | 651 | 974 652 | 653 | INPUT : 654 | 655 | Enter the array size : 6 656 | Enter the elements : 1 4 89 73 9 7 657 | Enter number of digits : 5 658 | 659 | OUTPUT : 660 | 661 | 98973 662 | 89. Given an array of numbers and a window of size k. Print the maximum of numbers inside the window for each step as the window moves from the beginning of the array. 663 | INPUT : 664 | 665 | Enter the array size : 8 666 | Enter the elements : 1,3,5,2,1,8,6,9 667 | Enter the window size : 3 668 | 669 | OUTPUT : 670 | 671 | 5 5 5 8 8 9 672 | 90: Given a string, reverse only vowels in it; leaving rest of the string as it is. 673 | Input : abcdef 674 | Output : ebcdaf 675 | 91 : Write a program to check if the given words are present in matrix given below. The words can be left to right, top to bottom and the diagonals (in top to bottom direction) 676 | 677 | 92 : Write a program to form lines using given set of words. The line formation should follow below rules. 678 | i) Total characters in a single line excluding the space between the words and the favorite character should not exceed the given number. 679 | ii) Favorite character is case insensitive. 680 | iii) Words should not be broken up. Complete words alone should be used in a single line. A word should be used in one line only. 681 | 682 | 683 | 684 | Input : Max char per line = 10 685 | Favorite character = 'o' 686 | Words : Zoho, Eating, Watching, Pogo 687 | Loving, Mango 688 | Output : Watching Zoho 689 | Eating Mango 690 | Loving Pogo. 691 | 93. Adding 2 numbers 692 | Given 2 huge numbers as separate digits, store them in array and process them and calculate the sum of 2 numbers and store the result in an array and print the sum. 693 | Input: 694 | Number of digits:12 695 | 9 2 8 1 3 5 6 7 3 1 1 6 696 | Number of digits:9 697 | 7 8 4 6 2 1 9 9 7 698 | Output : 699 | 9 2 8 9 2 0 2 9 5 1 1 3 700 | 94.Given sorted array check if two numbers sum in it is a given 701 | value 702 | Input 703 | Array = {1 3 4 8 10 } N = 7 704 | output 705 | true 706 | 95. Compiuting value of sin (x) 707 | Input x = 30 n = 10 708 | output = 0.5 709 | Hint : The equation sin(x) = x – x^3 / 3! + x^5 / 5! – …. 710 | 711 | 712 | 713 | 96. Write function to find multiplication of 2 numbers using + 714 | operator You must use minimum possible iterations. 715 | Input: 3 , 4 716 | Output 12 717 | 97. Given array find maximum sum of contiguous sub array 718 | {-2 -3 4 -1 -2 1 5 -3} 719 | output 7 elements [ 4 -1 -2 1 5] 720 | 98. Given unsorted array find all combination of the element for a given sum. Order should be maintained. 721 | Input : 722 | 8 3 4 7 9 N=7 723 | Output 724 | {3 4 } {7} 725 | 99. Given an odd length word which should be printed from the middle of the word. 726 | The output should be in the following pattern. 727 | Example: 728 | Input: PROGRAM 729 | Output: 730 | G 731 | GR 732 | GRA 733 | GRAM 734 | GRAMP 735 | GRAMPR 736 | GRAMPRO 737 | 100. It is a program to implement Least Recently Used (LRU) concept. Given a key, if it is already existed then it should be marked as recently used otherwise a value should be stored which is given as input and marked as recently used. The capacity is to store only 10 key, value pairs. If the table is full and given a new key; the key, value pair which is not recently used should be deleted which gives feasibility to store the new key, value pair. 738 | 101. Given a few pairs of names in the order child, father. The input is a person name and level number. The output should be the number of children in that particular level for the person given. 739 | Example: 740 | Input: 741 | [ 742 | {Ram, Syam}, 743 | {Akil, Syam}, 744 | {Nikil, Ram}, 745 | {Subhash, Ram}, 746 | {Karthik, Akil} 747 | ]; 748 | 749 | 750 | 751 | Syam 2 752 | Output: 3 (Syam has Ram and Akil in level 1 and in level 2 he have Nikil, Subhash, Karthik. So the answer is 3). 753 | 101 Given an array of positive integers. The output should be the number of occurrences of each number. 754 | Example: 755 | Input: {2, 3, 2, 6, 1, 6, 2} 756 | Output: 757 | 1 – 1 758 | 2 – 3 759 | 3 – 1 760 | 6 – 2 761 | 102) Given an array, find the minimum of all the greater numbers for each element in the array. 762 | 763 | Sample: 764 | Array : {2, 3, 7, ¬1, 8, 5, 11} 765 | 766 | Output: 767 | {2¬>3, 3¬>5, 7¬>8, ¬1¬>2, 8¬>11, 5¬>7, 11¬>} 768 | 103) Find the largest sum contiguous subarray which should not have negative numbers. We have to print the sum and the corresponding array elements which brought up the 769 | sum. 770 | 771 | 772 | 773 | 774 | Sample: 775 | Array : {¬2, 7, 5, ¬1, 3, 2, 9, ¬7} 776 | 777 | Output: 778 | Sum : 14 779 | Elements : 3, 2, 9 780 | 104) Given a string, we have to reverse the string without changing the position of punctuations and spaces. 781 | 782 | Sample: house no : 123@ cbe 783 | Output: ebc32 1o : nes@ uoh 784 | 105) Given a 2D grid of characters, you have to search for all the words in a dictionary by 785 | moving only along two directions, either right or down. Print the word if it occurs. 786 | 787 | Sample : 788 | a z o l 789 | n x h o 790 | v y i v 791 | o r s e 792 | Dictionary = {van, zoho, love, are, is} 793 | 794 | Output: 795 | zoho 796 | love 797 | Is 798 | 799 | 106) Given a string, change the order of words in the string (last string should come first). 800 | Should use RECURSION 801 | 802 | Sample: one two three 803 | Output : three two one 804 | 805 | -------------------------------------------------------------------------------- /zoho 3rd round: -------------------------------------------------------------------------------- 1 | 1. It was System Design round for 2 hours time duration. Design an In-Memory file management system. 2 | • Module1: Create a new directory and file in all Levels. 3 | • Module2: List all directories and files. 4 | • Module3: Update file content. 5 | • Module4: Update directory and file names. 6 | • Module5: Delete directory and file. 7 | • Module6: Restore deleted directories and files. 8 | 9 | 2. Create an engine that can process the user query. The main focus is not the logic but System Design. 10 | 1. How the created query engine scales out perfectly even upon adding new features later? 11 | 2. How do we create a system that can handle the following inputs and process the input query? 12 | Question: 13 | 1. Given a table containing a set of 10 employees with respective fields: 14 | ID Name Age Designation Department Reporting To 15 | 2. Show all employee data 16 | 3. Process the query: 17 | 1. Get input from the user until presses exit. 18 | 2. Get field value to compare, comparison operator as input 19 | 1. If the field value is age (int data type), supported comparators: >, <, !=, == 20 | 2. If the field value is of string data type, supported comparators: ‘startswith’, ‘contains’, ‘endswith’, ‘notcontains’, ‘equals’ and ‘notequals’. 21 | 3. Use ‘AND’ in default for queries with multiple checks. 22 | 4. Eg: age > 30 and age < 50 and department contains finance and reporting to A 23 | 4. Show the reporting to hierarchy for the given employee name: J -> I -> F -> D -> C -> B-> A 24 | 5. Show the employees reporting to the given manager. 25 | 6. Show summary of Department, Designation, ReportingTo. 26 | 27 | 28 | 3. Question was to build an Employee record management app with 5 tasks to be executed to qualify the round. 29 | we can hard code the employee records in any data structure of our choice. 30 | Columns of the table are: EmpName, Age, Designation, Department, ReportingTo 31 | Task 1: Display all the Employee records in a table format. 32 | Task 2: Search records based on user give criteria.(this task is divided into two sub tasks) 33 | a. display option according to the column type 1.String – Equals, Notequals, Contains, Notcontains, startswith, endswith 2.Integer- <, >, =, !=, between. 34 | 35 | 36 | 37 | b. apply the same for multiple conditions using ‘AND’ for each condition. (similar to ‘where’ class in SQL using multiple columns). 38 | Task 3: print reporting tree of the given employee. 39 | Task 4: print the employees reporting to the given manager. 40 | Task 5: print summary of Department, Designation, ReportingTo.(menu driven) 41 | 42 | 4.event management 43 | 5.TICKET RESERVATION SYSTEM 44 | 1. first simple reservation for 50 seats from A to F. 45 | 2. After stations are added in middle like B, C, D, E. Where people can board any station and get down at any station assuming train is going from A to F. 46 | 3. Then Waiting list are to be added after 50 seats reserved and if any reserved seat is cancelled we have to check the waiting list and need to confirm the seat if possible. 47 | 4. After which we need to print the details of the PNR details. 48 | 49 | 50 | 6. The bank has initially three customers.There were around eight modules . 51 | 52 | 53 | 54 | 1. Account Login 55 | 2. Purchase 56 | Account Login 57 | Giving customer id and password .Password should be encrypted and stored 58 | Encryption is like A-> B, B->C 59 | a-> b, b->c, c->d 60 | 0->1, 1->2 61 | On successful login, it should print the account details 62 | 1.Create Gift Card 63 | 2. TopUp 64 | 3.Transaction History 65 | 4.Block 66 | 67 | 68 | 69 | 5.Logout 70 | 1.Create Gift Card 71 | Gift card with 5 digit card no and 4 digit pin number will be genrated 72 | 2.TopUp 73 | For topup, amount need to be reduced from main account balance and added to gift card 74 | 3.Transaction History 75 | Should print all the transaction details of a particular gift card 76 | 4.Block 77 | If the card is blocked, shouldn’t be available for topUp, Purchase.the amount in gift card should be transferred to main account 78 | 5.Logging Out 79 | After log out, should go to main module, 80 | 81 | 2.Purchase 82 | Login to the gift card 83 | Purchase Amount 84 | Then print Available balance 85 | 7.Redeem points : 86 | For Every 100 rupee purchase, 1 reward point is added .For 10 reward points, 10 will be added to main account 87 | 8.Doing for Multiple gift cards 88 | 89 | 90 | 91 | 92 | 93 | ->BOMBARDED MAN GAME 94 | 95 | 96 | Design a system with following functionalities, 97 | 1. SET a variable 98 | 2. GET a variable 99 | 3. UNSET a variable 100 | 4. COUNT NUMBERS OF VARIABLE with given value 101 | 5. BEGIN — Begins a new transaction 102 | 6. ROLLBACK — Roll back all the commands in the open transaction 103 | 7. COMMIT — Commit the transaction 104 | EXAMPLE 1: 105 | 106 | 107 | 108 | SET a 20 109 | GET a 20 110 | SET b 30 111 | GET b 30 112 | SET a 10 113 | GET a 10 114 | UPDATE c 40 No variable named “c” 115 | SET c 30 116 | COUNT 30 2 117 | COUNT 40 null 118 | UNSET a 119 | GET a null 120 | EXAMPLE 2: 121 | GET a null 122 | SET a 30 123 | GET a 30 124 | EXAMPLE 3: 125 | SET a 30 126 | BEGIN 127 | GET a 30 128 | SET a 40 129 | GET a 40 130 | SET b 40 131 | GET b 40 132 | ROLLBACK 133 | GET b null 134 | GET a 30 135 | EXAMPLE 4: 136 | BEGIN 137 | SET a 40 138 | SET b 40 139 | SET c 50 140 | COUNT 40 2 141 | BEGIN 142 | COUNT 40 null 143 | COMMIT 144 | COUNT 40 2 145 | BEGIN 146 | SET c 10 147 | GET c 10 148 | ROLLBACK 149 | GET c 50 150 | 151 | 152 | Round 3: 153 | Given an employee date base. 154 | 155 | 156 | 157 | Name, Age, Designation, Department Of ten people. 158 | and Five tasks were given such as 159 | 1. Print all employee details. 160 | 2. Searching employee details 161 | 3. Employees under the given manger name of the department 162 | 4. reporting to tree of the given employee name 163 | 164 | 165 | 166 | ->RAILWAY RESERVATION SYSTEM 167 | 1. In these rounds we were asked to implement the logic for 2 games 168 | – Minesweeper 169 | 170 | 2. – Breakout a.k.a. Arkanoid a.k.a. Brick-Breaker (you’ll find it online) 171 | 172 | 173 | The application was TOLL PAYMENT PROCESSING . 174 | They insisted us to do it in a object oriented language. First they asked the design( what are all the classes and objects & what data structure do you use). 175 | Application description: 176 | • 177 | • There are ‘n’ number of points in a highway out of which some points collect toll. 178 | • Each toll has its own charging scheme according to the vehicles and whether or not they 179 | are a VIP user. 180 | • If they are VIP user, 20% discount apply. 181 | • If the vehicle passes 3 toll gates, it has to pay in all the 3 toll gates according to the 182 | scheme of respective tolls. 183 | There were 4 modules. 184 | 1. Given the details of vehicle type, start and destination……display the total toll paid during 185 | the journey and print the amount after applying the discount. 186 | 187 | 188 | 2. Display the details of all the tolls…..like what are all the vehicles(vehicle number) passed 189 | that respective toll and the amount each vehicle paid……and the total amount charged in 190 | that toll. 191 | 3. Display the details of all the vehicles …….like what are all the journeys did it take….the 192 | start and destination of the same……tolls it passed during that journey….amount paid in 193 | that journey…..and the total amount paid by that vehicle. 194 | 4. Assume the highway as a circular path……we have to find the short route and identify 195 | the tolls between that route and calculate the amount. 196 | 197 | --------------------------------------------------------------------------------