Interview Question

Country: United States

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

If I understand correctly, the program should do the following:
1) preserve first character as-is (since the change in case is happening starting after 2nd character)
2) all characters after the second character should be lower case EXCEPT every 3rd character

ex: abcdefghij -> aBcdEfgHij
aBCDEFGHIJ -> aBcdEfgHij

public static void main(String [] args){
        String test = "bcdefghij";


    public static String camelCaseEveryKChars(String origString, int k){
        int offset = 1; //start from second character

        StringBuffer result= new StringBuffer(origString.substring(0, offset)); //add first 2 letters as is.

        for(int i=offset; i< origString.length(); i++) {
        return result.toString();

- Fahimeh.Fakour February 21, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

If I understood your statement correct, starting 2 alphabet and every 3rd occurrence should be upper case.
ex: abcdefghij -> aBcdEfgHij

String str = "abcdefghij";
		for(int i = 1; i < str.length(); i=i+3) {
			str = str.replace(str.charAt(i), Character.toUpperCase(str.charAt(i)));

- basu February 17, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 votes

This solution doesn't ensure all other characters are lower case.
ex: for the string ABCDEFGHIJ your code would return ABCDEFGHIJ. while the expected result (from what I understand from the question): ABcdEfgHij

- Fahimeh.Fakour February 21, 2018 | Flag

Add a Comment

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


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


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