IBM Interview Question for Software Engineer / Developers


Country: United States




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

// ZoomBA 
// whole string 
def reverse( string , si, ei ){
   fold( [ si : (si + ei + 1)/2 ] ) ->{
     t = string.value[ $.item ]
     string.value[ $.item ] = string.value[ ei - $.index ]
     string.value[ ei - $.index ] = t
   }
}
// If you want to reverse the words, 
def reverse_words( string ){
  reverse( string , 0, #|string| - 1 )
  si = 0 ; ei = 0
  len = #|string|
  while ( true  ){
    while ( si < len && string[si] ==' ' ) { si += 1 }
    break ( si >= len )
    ei = si
    while ( ei < len && string[ei] !=' ' ) { ei += 1 }
    break ( ei >= len ){ reverse( string, si, len-1 )}
    reverse( string, si, ei - 1 )
    si = ei
  }
}

- NoOne October 13, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

@NoOne: I am sorry to ask this, but is this java??

- abhinav.thegame October 13, 2016 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

No, Abhinav, it is not.It is called ZoomBA.
You can take it as a certain pseudo lang if you wish too.
You can read more about it here : gitlab.com/non.est.sacra/zoomba
Albeit, is a declarative fully functional language on its own.

- NoOne October 13, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thank you NoOne for your comment. Is there any online compiler available for this language that I can test your pseudo code at? That will help me to know your code more and convert it to python or java

- abhinav.thegame October 13, 2016 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ReverseToString {

	public static void main(String[] args) {

		String inp = "How Are You Doing Today";

		boolean firstWord = false;
		for (int i = inp.length() - 1; i >= 0; i--) {

			if (firstWord == false) {

				System.out.print(String.valueOf(inp.charAt(i)).toUpperCase());

				firstWord = true;

			} else if (String.valueOf(inp.charAt(i)).equals(" ")) {

				System.out.print(" "
						+ String.valueOf(inp.charAt(i - 1)).toUpperCase());

				i = i - 1;

			} else {

				System.out.print(String.valueOf(inp.charAt(i)).toLowerCase());
			}

		}

	}

}

- Sandy0109 October 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def reverseString(s):
    s = s[::-1].lower().strip()
    li = list(s)
    print li
    fin = ""
    for i in range(len(s)):
        if i == 0:
            li[i] = li[i].upper()
        elif li[i] == " ":
            li[i+1] = li[i+1].upper()
        fin += li[i]
    return fin

- Anonymous October 15, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def reverseString(s):
    s = s[::-1].lower().strip()
    li = list(s)
    print li
    fin = ""
    for i in range(len(s)):
        if i == 0:
            li[i] = li[i].upper()
        elif li[i] == " ":
            li[i+1] = li[i+1].upper()
        fin += li[i]
    return fin

- ASB October 15, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
int main()
{
printf("Enter the string");
reverse();
}
reverse()
{
char ch;
scanf("%c",&ch);
if(ch!='\n')
{
reverse();
printf("%c",ch);
}
}
output: enter the string
hello world
dlrow olleh

- ravishekhar s October 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In C#

private static void ReverseString(string sentence)
        {
            if (sentence.Contains(" "))
            {
                char[] seperator = { ' ' };
                string[] words = sentence.Split(seperator);
                string[] reversedWords = new string[10];

                int increment = 0;
                foreach (string word in words)
                {
                     string reverdedword = new string(word.Reverse().ToArray());

                    reversedWords[increment] = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(reverdedword);
                    increment++;
                }

                string[] weversedColletion = reversedWords.Reverse().ToArray();

                Console.Write(string.Join(" ",weversedColletion));
            }
        }

- SK October 27, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private static void ReverseString(string sentence)
        {
            if (sentence.Contains(" "))
            {
                char[] seperator = { ' ' };
                string[] words = sentence.Split(seperator);
                string[] reversedWords = new string[10];

                int increment = 0;
                foreach (string word in words)
                {
                     string reverdedword = new string(word.Reverse().ToArray());

                    reversedWords[increment] = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(reverdedword);
                    increment++;
                }

                string[] weversedColletion = reversedWords.Reverse().ToArray();

                Console.Write(string.Join(" ",weversedColletion));
            }
        }

- SK October 28, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ReverseString {

	public static void main(String[] args) {
		String input1 = "Hello World";
		String input2 = "How is the weather today !";
		System.out.println(reverseString(input1));
		System.out.println(reverseString(input2));
	}

	private static StringBuilder reverseString(String input) {
		StringBuilder result = new StringBuilder();
		String[] words = input.split(" ");
		for(int i=(words.length - 1); i>=0; i--) {
			for(int j=(words[i].length() - 1); j>=0; j--) {
				if( j == (words[i].length() - 1))
					result.append(String.valueOf(words[i].charAt(j)).toUpperCase());
				else if( j == 0)
					result.append(String.valueOf(words[i].charAt(j)).toLowerCase());
				else
					result.append(String.valueOf(words[i].charAt(j)));
			}
			if(i!=0)
				result.append(" ");
		}
		return result;
	}
}

- MD November 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

reversed = reduce(lambda x,y:y+x, string)

- Anonymous November 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static StringBuilder revSentence(String str) {
StringBuilder sb = new StringBuilder();
sb.append(str);
return sb.reverse();
}

- goldnBear November 19, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

namespace String
{

static class StringWorkAround
{
public static string stringreverser(string s)
{
char[] array1 = s.ToCharArray();
Array.Reverse(array1);
//to lower all chars

for (int K = 1; K < array1.Length; K++)
{
array1[K] = char.ToLower(array1[K]);
}

if (array1.Length >= 1)
{

array1[0] = char.ToUpper(array1[0]);



}
// Scan through the letters, checking for spaces.
// ... Uppercase the lowercase letters following spaces.
for (int K = 1; K < array1.Length; K++)
{
if (array1[K - 1] == ' ')
{

array1[K] = char.ToUpper(array1[K]);


}
}
return new string(array1);
}
}


class Program
{
static void Main(string[] args)
{
Console.WriteLine(StringWorkAround.stringreverser("Hello World"));
//Console.WriteLine(StringWorkAround.stringreverser("Happy New Year"));
Console.WriteLine(StringWorkAround.stringreverser("How Are YOu Doing Today"));



}
}
}

- SAM December 18, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

namespace String
{

static class StringWorkAround
{
public static string stringreverser(string s)
{
char[] array1 = s.ToCharArray();
Array.Reverse(array1);
//to lower all chars

for (int K = 1; K < array1.Length; K++)
{
array1[K] = char.ToLower(array1[K]);
}

if (array1.Length >= 1)
{

array1[0] = char.ToUpper(array1[0]);



}
// Scan through the letters, checking for spaces.
// ... Uppercase the lowercase letters following spaces.
for (int K = 1; K < array1.Length; K++)
{
if (array1[K - 1] == ' ')
{

array1[K] = char.ToUpper(array1[K]);


}
}
return new string(array1);
}
}


class Program
{
static void Main(string[] args)
{
Console.WriteLine(StringWorkAround.stringreverser("Hello World"));
//Console.WriteLine(StringWorkAround.stringreverser("Happy New Year"));
Console.WriteLine(StringWorkAround.stringreverser("How Are YOu Doing Today"));



}
}
}

- SAM December 18, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

namespace String
{

    static class StringWorkAround
    {
        public static string stringreverser(string s)
        {
            char[] array1 = s.ToCharArray();
            Array.Reverse(array1);
            //to lower all chars

            for (int K = 1; K < array1.Length; K++)
            {
                array1[K] = char.ToLower(array1[K]);
            }

                if (array1.Length >= 1)
            {
                
                    array1[0] = char.ToUpper(array1[0]);
                
                

            }
            // Scan through the letters, checking for spaces.
            // ... Uppercase the lowercase letters following spaces.
            for (int K = 1; K < array1.Length; K++)
            {
                if (array1[K - 1] == ' ')
                {
                    
                        array1[K] = char.ToUpper(array1[K]);
                   
                    
                }
            }
                return new string(array1);
            }
        }


        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine(StringWorkAround.stringreverser("Hello World"));
            //Console.WriteLine(StringWorkAround.stringreverser("Happy New Year"));
            Console.WriteLine(StringWorkAround.stringreverser("How Are YOu Doing Today"));



        }
        }
    }

- SAM December 18, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Reverse_string
{
public static void main(String args[])
{
String original, reverse="";
Scanner in=new Scanner(System.in);
System.out.println("Enter the reverse string:");
original=in.nextLine();

int length=original.length();
for(int i=length-1; i>=0; i--)
{
reverse=reverse+original.charAt(i);
}

System.out.println("Reversed string is:" +reverse);

}
}

- Anonymous January 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Reverse_string
{
public static void main(String args[])
{
	String original, reverse="";
	Scanner in=new Scanner(System.in);
	System.out.println("Enter the reverse string:");
	original=in.nextLine();
	
	int length=original.length();
	for(int i=length-1; i>=0; i--)
	{
		reverse=reverse+original.charAt(i);
	}
	
	System.out.println("Reversed string is:" +reverse);

}
}

- kumudaramanathan January 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Was this reverse a string problem asked in the Guru interview, or the initial hirevue challenge?

- wonderkid February 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Scanner;

public class Reversal_2 {
	public static void main(String[] args) {
		System.out.println("enter the sentence");
		Scanner s = new Scanner(System.in);
		String input = s.nextLine();
		input = input.toLowerCase();
		String reversed = recursive(input);

		char[] array = reversed.toCharArray();
		int len = reversed.length();
		array[0] = Character.toUpperCase(array[0]);
		System.out.print(array[0]);
		for (int i = 1; i < len; i++) {
			if (array[i] == ' ')
				array[i + 1] = Character.toUpperCase(array[i + 1]);
			System.out.print(array[i]);

		}
	}

	private static String recursive(String input) {
		if (input.length() <= 1 || input == null)
			return input;

		return recursive(input.substring(1)) + input.charAt(0);
	}

}

- undefined April 18, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class reverseString {
    public static void main(String[] args) {
        String first = "How Are You Doing Today";

        System.out.println(reverse(first));
    }

    private static String reverse(String first) {

        StringBuilder test = new StringBuilder();
        boolean space = false;

        test.append(Character.toUpperCase(first.charAt(first.length() - 1)));

        for (int i = first.length() - 2; i >= 0; i--) {

            if (Character.isUpperCase(first.charAt(i))) {
                test.append(Character.toLowerCase(first.charAt(i)));
                space = false;
            } else if (first.charAt(i) == ' ') {
                space = true;
                test.append(first.charAt(i));
            } else if (space) {
                test.append(Character.toUpperCase(first.charAt(i)));
                space = false;
            } else {
                space = false;
                test.append(first.charAt(i));
            }
        }
        return test.toString();
    }
}

- Zach December 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class reverseString {
    public static void main(String[] args) {
        String first = "How Are You Doing Today";

        System.out.println(reverse(first));
    }

    private static String reverse(String first) {

        StringBuilder test = new StringBuilder();
        boolean space = false;

        test.append(Character.toUpperCase(first.charAt(first.length() - 1)));

        for (int i = first.length() - 2; i >= 0; i--) {

            if (Character.isUpperCase(first.charAt(i))) {
                test.append(Character.toLowerCase(first.charAt(i)));
                space = false;
            } else if (first.charAt(i) == ' ') {
                space = true;
                test.append(first.charAt(i));
            } else if (space) {
                test.append(Character.toUpperCase(first.charAt(i)));
                space = false;
            } else {
                space = false;
                test.append(first.charAt(i));
            }
        }
        return test.toString();
    }
}

- Zach December 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def rev(stri):
stri = stri[::-1].lower().split()
return' '.join([s[0].upper()+s[1:] for s in stri])

- Anonymous March 06, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

public String reverseWordsInString(String s){
        if(s == null || s.length() == 0 ||  s.trim().length() == 0){
            return s;
        }
        String[] words = s.split(" ");
        String[] revWords = new String[words.length];
        for(int i=0; i<words.length;i++){
            String word = words[i].trim();
            char[] revW = reverseWord(word);
            revWords[i] = new String(revW);
        }
        StringBuilder builder = new StringBuilder();
        for(int i=revWords.length-1;i>=0;i--){
            builder.append(revWords[i]).append(" ");
        }
        return builder.toString();
    }

  private char[] reverseWord(String word){
        int j = word.length()-1;
        int k =0;
        char[] rWord = new char[word.length()];
        char[] wordA =		word.toCharArray();
        while(j >=k){
            if(k==0){
                rWord[k]=  Character.toUpperCase(wordA[j]);
                rWord[j-k]= Character.toLowerCase(wordA[k]);
            } else if(j ==k){
                rWord[k] = wordA[j];
            }
            else {
                rWord[k] = wordA[j];
                rWord[j] = wordA[k];
            }
            j--;
            k++;
        }
        return rWord;
    }

- itsMe October 13, 2016 | 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