Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: In-Person
1.take number of inputs.(n)
2.parse each input into char and store dem in an array.input[n][c] ex:input[1][0] is 1st char of 1st input
3.for loop with n intialised to 0,
3.a)if c<5 print -1 as o/p ,increment n and repeat procedure
4.else check if (input[n][0]='L')if yes check input[n][1],if no replace the char wid L and increment count[n]
5.and check if (input[n][1]='i')if yes check input[n][2],if no replace the char wid I and increment count[n]
6.have a for loop and check if (input[n][2]='n')--(input[n][n-3])='n'if y check input[n][n-2],else replace the chars wid n and increment count[n] for each replacement.
7.and check if (input[n][n-2]='u')if yes check input[n][n-1],if no replace the char wid u and increment count[n]
7.similarly check if (input[n][n-1]='x')if yes , display count[n]and increment n and repeat the procedure till for next n,if no replace the char wid x and increment count[n] and display
8.Repeat procedure for all inputs
with CTLIN as (
select input, len(input)- len(replace(INPUT, 'L', '')) as L, len(input)- len(replace(INPUT, 'i', ''))as I,
len(input)- len(replace(INPUT, 'n', '')) as N, len(input)- len(replace(INPUT, 'u', '')) as U,
len(input)- len(replace(INPUT, 'x', '')) as X
from LIN)
select input from CTLIN where L=1 and I=1 and N>=1 and U=1 and X=1
This seems really easy... each string must start with "LI" and end with "UX", and between I can only find "N"s (all characters might have an upper or lower case). So I can simply scan the string and prompt for a character replacement if it is different from what I expect. Obviously, since I cannot insert any character, if the string has less than 5 characters, the output is -1.
In Java:
- Matteo February 04, 2012