Oracle Interview Question for Software Engineer / Developers






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

// Write a method to replace all spaces in a string with '%20'.
	// COMPLEXITY O (N + 2 * #SPACES ) O (N)  AVG
	public static char[] replaceSpaces(char str[]){
		int spaces = 0;
		for(int i = 0; i < str.length; i++){
			if(str[i] == ' '){
				spaces++;
			}
		}
		int length = str.length + (2*spaces);
		char result [] = new char[length];
		int index = 0;
		for(int i = 0; i < str.length; i++){
			if(str[i] == ' '){
				result[index++] = '%';
				result[index++] = '2';
				result[index++] = '0';
			}else{
				result[index++] = str[i];
			}
		}
		return result;
	}

- .·´¯`·.´¯`·.¸¸.·´¯`·.¸><(((º> January 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public String replace(String txt){
int sp= 0;
char [] chs = txt.toCharArray();
for (int i =0 ;i<chs.length ;++i){
if (chs[i] ==' '){
sp++;
}
}
char [] n_ch = new char [txt.length()+sp*2];
int j =0;
for (int i = 0 ;i<chs.length ;++i){
if (chs[i]==' '){
n_ch[j] = '%';
n_ch[j+1] = '2';
n_ch[j+2] = '0';
j+=3;
}else{
n_ch[j++] = chs [i] ;
}
}
return new String(n_ch);

}

- Scott January 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String replaceSpacesWithCrap(String someString, String crap){
return someString.replaceAll("\\s", crap); //crap="20"
}

- Zakon June 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<stdlib.h>
using namespace std;

int main()
{
char myString[] = "Mrs. Vathsala Nagaraju ";
cout << endl << myString;
int n, k, i, x;
n = k = strlen(myString);
cout << endl << "value of k and n are " << k << " and " << n;
k = n = n - 1;

while (myString[n] == ' ') n = n - 1;

k = k - n;

for (i = n; i > 0; i--)
{
if (myString[i] != ' ')
{
while (myString[i] != ' ')
{
myString[i + k] = myString[i];
i = i - 1;
}
k = k - 2;
myString[i+k] = '%';
myString[i+k+1] = '2';
myString[i+k+2] = '0';

}

}
cout << endl << myString;
cin >> x;
return 0;
}

- Lakshman M P August 09, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<stdlib.h>
using namespace std;

int main()
{
char myString[] = "Mrs. Vathsala Nagaraju ";
cout << endl << myString;
int n, k, i, x;
n = k = strlen(myString);
cout << endl << "value of k and n are " << k << " and " << n;
k = n = n - 1;

while (myString[n] == ' ') n = n - 1;

k = k - n;

for (i = n; i > 0; i--)
{
if (myString[i] != ' ')
{
while (myString[i] != ' ')
{
myString[i + k] = myString[i];
i = i - 1;
}
k = k - 2;
myString[i+k] = '%';
myString[i+k+1] = '2';
myString[i+k+2] = '0';

}

}
cout << endl << myString;
cin >> x;
return 0;
}

- lakshman M P August 09, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<stdlib.h>
using namespace std;

int main()
{
char myString[] = "Mrs. Vathsala Nagaraju ";
cout << endl << myString;
int n, k, i, x;
n = k = strlen(myString);
cout << endl << "value of k and n are " << k << " and " << n;
k = n = n - 1;

while (myString[n] == ' ') n = n - 1;

k = k - n;

for (i = n; i > 0; i--)
{
if (myString[i] != ' ')
{
while (myString[i] != ' ')
{
myString[i + k] = myString[i];
i = i - 1;
}
k = k - 2;
myString[i+k] = '%';
myString[i+k+1] = '2';
myString[i+k+2] = '0';

}

}
cout << endl << myString;
cin >> x;
return 0;
}

- lakshman M P August 09, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<stdlib.h>
using namespace std;

int main()
{
	char myString[] = "Mrs. Vathsala Nagaraju    ";
	cout << endl << myString;
	int n, k, i, x;
	n = k = strlen(myString);
	cout << endl << "value of k and n are " << k << " and " << n;
	k = n = n - 1;

	while (myString[n] == ' ') n = n - 1;

	k = k - n;

	for (i = n; i > 0; i--)
	{
		if (myString[i] != ' ')
		{
			while (myString[i] != ' ')
			{
				myString[i + k] = myString[i];
				i = i - 1;
			}
			k = k - 2;
			myString[i+k] = '%';
			myString[i+k+1] = '2';
			myString[i+k+2] = '0';
			
		}

	}
	cout << endl << myString;
	cin >> x;
	return 0;
}

- lakshman M P August 09, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<stdlib.h>
using namespace std;

int main()
{
	char myString[] = "Mrs. Vathsala Nagaraju    ";
	cout << endl << myString;
	int n, k, i, x;
	n = k = strlen(myString);
	cout << endl << "value of k and n are " << k << " and " << n;
	k = n = n - 1;

	while (myString[n] == ' ') n = n - 1;

	k = k - n;

	for (i = n; i > 0; i--)
	{
		if (myString[i] != ' ')
		{
			while (myString[i] != ' ')
			{
				myString[i + k] = myString[i];
				i = i - 1;
			}
			k = k - 2;
			myString[i+k] = '%';
			myString[i+k+1] = '2';
			myString[i+k+2] = '0';
			
		}

	}
	cout << endl << myString;
	cin >> x;
	return 0;

}

- Lakshman M P August 09, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Public static string removeSpaces(String testString)
{
	for (int i=0; i<testString.length();i++)
{
if testString.charAt(i) == ‘ ‘ then
testString = testString.substring(0, i) + “%20” + testString.substring(i+1,string.length())
	}
	return testString;

}

- Anonymous August 19, 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