Oracle Interview Question for Software Engineer / Developers






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

i think xoring of all integers values of characters should be 0 if they are anagram.

- amit January 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Great answer!!! (y)

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

i don't think so... aabbccdd and ffgghhii will give xor as 0

- harinath July 18, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

// Write a method to decide if two strings are anagrams or not.
	// Complexity O ( 2n + k)  avg, since s1 and s2 should contains the same length otherwise It will return false immediate
	public static boolean isAnagram(char s1[], char s2[]){
		if(s1.length != s2.length) return false;
		int letters [] = new int[256];
		for( int i = 0; i < s1.length; i++){
			letters[toUpperCase(s1[i])]++;
		}
		for( int j = 0; j < s2.length; j++){
			letters[toUpperCase(s2[j])]--;
			if(letters[toUpperCase(s2[j])] < 0) return false;
		}
		for(int x = 0; x < letters.length; x++){
			if(letters[x] != 0 ) return false;
		}
		return true;
	}

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

What if you character set is not ASCII (256) but UNICODE (2^16 or something)? The complexity of the above solution would be enormous.

- Learner January 27, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I would be worse if you try to save each letter and iterate one by one. the complexity will be >= O (n square )

I dont see a better solution. do you ?

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

Just sort the 2 strings and compare, O(nlogn)

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

public static boolean isAnagram(String word, String anagram) { 
		if(word.length() != anagram.length())
			return false; 
		char[] chars = word.toCharArray(); 
		for(char c : chars)
		{ 
			int index = anagram.indexOf(c); 
			if(index != -1){ 
				anagram = anagram.substring(0,index) + 
						anagram.substring(index +1, anagram.length()); 
				}
			else { 
				return false; 
				} 
		} 
		return anagram.isEmpty(); 
	}

Time Complexity: O(n)

- Vaibhavs February 16, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static boolean IsAnagram(String str1, String str2){
if(str1.length() != str2.length()){
return false;
}
char[] charArr1 = str1.toLowerCase().toCharArray();
char[] charArr2 = str2.toLowerCase().toCharArray();

Character c;
int hashCodeValue1 =0;
int hashCodeValue2 =0;
for(int i=0;i<charArr1.length;i++){
c = charArr1[i];
hashCodeValue1+=c.hashCode();
}
for(int i=0;i<charArr2.length;i++){
c = charArr2[i];
hashCodeValue2+=c.hashCode();
}

if(hashCodeValue1 == hashCodeValue2)
return true;

return false;
}

- Sanal February 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i don't know how to code yet, but here are the steps i think are needed:
1) take both strings in two seperate variables
2) compare length of variables if yes then goto next step
3) reverse any string, then compare with the other string. if yes then anagram

- myFirstCode June 06, 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