is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
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.
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.
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.
import java.util.HashMap;
- dhavalmodasa December 22, 2015import java.util.Map;
/**
* Find first non repeated element from unsorted array.
*
* Time complexity:O(1) Space complexity:O(n), here n is number of elements in
* the array.
*
* @author dmpatel
*
*/
public class FindFirstNonRepeatedElement {
public static void main(String[] args) {
int a1[] = new int[] { 5, 7, 8, 9, 2, 3, 5, 2, 7, 0 };
int a2[] = new int[] { 5, 7, 8, -1, 0, 4 };
try {
int element = findFirstNonRepeatedElement(a1);
System.out.println("First Non Repeated Element=" + element);
} catch (InvalidInputException e) {
System.out.println(e.getMessage());
}
}
private static int findFirstNonRepeatedElement(int[] a)
throws InvalidInputException {
Integer element = null;
if (null == a || a.length == 0) {
throw new InvalidInputException("Invalid input");
}
int aLength = a.length;
Map<Integer, Boolean> map = new HashMap<Integer, Boolean>(aLength);
int aElement = 0;
for (int i = 0; i < aLength; i++) {
aElement = a[i];
if (!map.containsKey(aElement)) {
map.put(aElement, true);
} else {
map.put(aElement, false);
}
}
for (int i = 0; i < aLength; i++) {
aElement = a[i];
if (!map.get(aElement)) {
element = aElement;
break;
}
}
if (null == element) {
throw new InvalidInputException("Invalid input");
}
return element;
}
}
class InvalidInputException extends Exception {
public InvalidInputException(String message) {
super(message);
}
/**
* Generated serial version id.
*/
private static final long serialVersionUID = 5890758270469708368L;
}