Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
2
of 2 vote

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:

package quiz;

public class Linux {

	public static void main(String[] args) {
		String[] strings = new String[] {
				"Linux",
				"LinnnnnUx",
				"LNux",
				"Codecrackers"
		};
		
		for (String s : strings) {
			int changes = check(s.toCharArray());
			System.err.println(s + " -> " + changes);
		}
	}

	public static int check(char[] s) {

		if(s.length < 5) return -1;

		int changes = 0;
		if(s[0] != 'l' && s[0] != 'L') changes++;
		if(s[1] != 'i' && s[1] != 'I') changes++;

		for(int i = 2; i < s.length-2; i++)
			if(s[i] != 'n' && s[i] != 'N') changes++;

		if(s[s.length-2] != 'u' && s[s.length-2] != 'U') changes++;
		if(s[s.length-1] != 'x' && s[s.length-1] != 'X') changes++;

		return changes;
	}
}

- Matteo February 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- Kaushik February 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- Pramod July 30, 2017 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More