Evan
BAN USER- 1of 1 vote
AnswersGiven the two arrays with integers, return the common elements
- Evan in United States| Report Duplicate | Flag | PURGE
Microsoft - 1of 1 vote
AnswersGiven the string of parentheses only, write the function to check if they are balanced. ((())) is balanced, )( is not.
- Evan in United States
Follow up: Now the string also contains curly and square braces. You already have boolean functions, isOpenBrace() , isCloseBrace() and bracesMatch(char brace1, char brace2) as required. How do you check if braces are balanced?| Report Duplicate | Flag | PURGE
Microsoft - 0of 0 votes
AnswersGiven an array of integers, return the first integer which occurs only once in O(n).
- Evan in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Data Structures
import java.util.*;
public class Unique {
static public void main(String[] args){
char[] A ={'a','a', 'u', 'b'};
System.out.println("First unique element is "+findUniqueFirstCharFromArray(A));
}
public static char findUniqueFirstCharFromArray(char[] a){
char uniqueChar=0;
HashMap<Character,Boolean> intMap = new HashMap<Character, Boolean>();
for(int i=0;i<a.length;i++){
if(intMap.containsKey(a[i]) ){
intMap.put(a[i], true);
}
else {
intMap.put(a[i], false);
}
}
for(int i=0;i<intMap.size();i++)
if(intMap.get(a[i])==false){
uniqueChar=a[i];
break;
}
return uniqueChar;
}
}
Yep. That means there can be any number of spaces. So you cannot simply store single space between words in your method
- Evan December 26, 2012