Capgemini Interview Question for Senior Software Development Engineers


Country: India
Interview Type: Phone Interview




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

// Time : O(n), Space : O(n)
// In java, string manipulations cannot be done in constant space
public static String reverseSetence(String str) {
		StringBuilder sb = new StringBuilder(str);
		Pattern p = Pattern.compile("[a-zA-Z0-9]+");
		Matcher m = p.matcher(str);
		while (m.find()) {
			reverse(sb, m.start(), m.end() - 1);
		}
		return sb.toString();
	}

	public static void reverse(StringBuilder sb, int l, int r) {
		while (l < r) {
			swap(sb, l++, r--);
		}
	}

	public static void swap(StringBuilder sb, int i, int j) {
		char temp = sb.charAt(i);
		sb.setCharAt(i, sb.charAt(j));
		sb.setCharAt(j, temp);
	}

- Raj March 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

#include<iostream>
#include<vector>
#include<string>

using namespace std;

string func(string s){

        vector<char> v;
        string s2="";

        for(int i=0;i<s.size();i++){
                if(s[i]==' ' || i==s.size()-1){
                        if(i==s.size()-1) v.push_back(s[i]);
                        while(v.size()){
                                s2=s2+v[v.size()-1];
                                v.pop_back();
                        }
                        s2=s2+' ';
                }
                else
                        v.push_back(s[i]);
        }
        return s2;
}

int main(){

        string s = "We will rock you !";
        cout<<func(s)<<endl;

        return 0;
}

- Tarun March 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

python:

sentence = "This is a sentence"
reverse = " ".join(word[::-1] for word in sentence[::-1].split(" "))
print reverse	# sentence a is This

- ninhnnsoc March 12, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1 #!/usr/bin/python
2
3 import sys
4 import time
5
6
7
8 def rev_string(input_data):
9 # Create an empty List Obj for later use
10 final_list = []
11 # Transform and fill a local Obj with the input data
12 my_list = list(input_data)
13 # Getting the range(Len of the list -1, End, Step_Val)
14 range_data = range(len(my_list) - 1, -1, -1)
15 # Start a for loop to step the range data
16 for data_step in range_data:
17 # Fill the list Obj we created at the start
18 final_list.append(my_list[data_step])
19 # once we have appended the data, we then join it back and return
20 final_list = ''.join(final_list)
21 return final_list
22
23
24 def main():
25 # input data
26 data = "This is a string!"
27 # Show the user data before
28 print "Data Before: %s" % data
29 # call the rev function to flip the data
30 data = rev_string(data)
31 # Show the user data after
32 print "Data After: %s" % data
33
34 if __name__ == "__main__":
35 sys.exit(main())



Example output -- >
Data Before: This is a string!
Data After: !gnirts a si sihT

- schoettger.aaron March 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// c or c++ version
// no error checking is done
void revString(char *str, int start, int end)
{
	char temp;
	while (start < end) {
		temp = str[start];
		str[start] = str[end];
		str[end] = temp;
		start++;
		end--;
	}
}
// Assumption - one space between words
void revSentence( char *sen)
{
	int len = strlen(sen);
	if (len == 0 || len == 1) return;
	// reverse string
	revString(sen, 0, len-1);
	int start =0;
	for (int i=0; i<len; i++) {
		// if it is space, reverse the word
		if (sen[i] == ' ') {
			revString(sen, start, i-1);
			start = i+1;
		}
	}
	// reverse last word
	revString(sen, start, len-1);
}

- AD March 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def ReverseString(str)
print(str[::-1])

//test
assert ReverseString("hello world") = "dlrow oleo"

- Stephen Chen March 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In Javascript:
function RevSentence(str)
{
var ss = str.split("").reverse().join("");
console.log(ss);

}

RevSentence("Welcome to jurassic park");

- Jaideep July 18, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

reverse the string and print words from en

- gupta ji March 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

#include<stdio.h>
#include<string.h>

int main() {
char str[100], temp;
int i, j = 0;

printf("\nEnter the string :");
gets(str);
i = 0;
j = strlen(str) - 1;
while (i < j) {
temp = str[i];
str[i] = str[j];
str[j] = temp;
i++;
j--;
}
printf("\nReverse string is :%s", str);
return (0);
}

- Saurav garg March 11, 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