Linkedin Interview Question for Software Developers


Team: Mobile
Country: United States
Interview Type: Phone Interview




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

1. If the elements in the array are less than size of the array then go for following algorithm

traverse the list for i= 0 to n-1 elements
{
  check for sign of A[abs(A[i])] ;
  if positive then
     make it negative by   A[abs(A[i])]=-A[abs(A[i])];
  else  // i.e., A[abs(A[i])] is negative
     this   element (ith element of list) is a repetition
}

2. Otherwise you can use data structure like HashMap.

- Rushikesh Gaidhani September 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Sort the array, all same numbers will be next to each other, compare number with the previous one if they are same print it, otherwise move on.

public static void findDuplicateNumber() {
		int[] array = { 1, 1, 2, 3, 4, 4, 5, 8, 8, 9, 10, 12, 12, 18 };
		System.out.println("Origianl Array = " + Arrays.toString(array));

		for (int i = 0; i <= array.length - 2; i++) {
			if (array[i] == array[i + 1]) {
				System.out.print(array[i] + ",");
				i = i + 1;
			}

		}
	}

This should give us O(n log n) time complexity. does it look right?

- LookingForJob September 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

This problem seems very easy. If you use Hashmap, the time complexity is O(n) and space complexity is also O(n). Since you were interviewed by the mobile team, I bet they were looking for solutions with O(1) space complexity.

- jiahuang September 15, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

// From ZoomBA , with Love 
def not_sorted( a ){
   select ( mset( a ) ) :: { $.o.value > 1 } -> { $.o.key }
}

- NoOne October 08, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Scala one liner...

array.filter(number => array.count(_ == number) > 1).groupBy(x => x).map{case (k,v) => k -> v.length}

- vireshjivane5 December 01, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This could probably be solve with a Hashset and you wouldn't need to sort the array. You would loop through the array and for each element check if it is contained in the set (which is O(1) ) and if it is add it to a list otherwise add it to the set and return the list. The time complexity would be O(n).

public static List<Integer> findDuplicates(int[] arr){
		Set<Integer> store = new HashSet<Integer>();
		List<Integer> dups = new ArrayList<Integer>(); 
		for(int i = 0; i < arr.length; i++){
			if(store.contains(arr[i])){
				dups.add(arr[i]);
			} else {
				store.add(arr[i]);
			}
		}
		return dups;

}

- opdante February 28, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// O(n) speed
std::vector<int> FindDuplicates(std::vector<int> input_array)
{
	std::unordered_map<int, int> hashTable;
	std::vector<int> output;
	for (int i=0; i < input_array.Size(); i++)
	{
		// find is O(1) on std::unordered_map
		if (hashTable.find(input_array[i]))
		{
			hashTable[i]++;
			if (hashTable[i] == 2)
			{
				out_put.push_back(input_array[i]);
			}
		}
		else
		{
			hashTable[i] = 1;
		}
	}

	return output;
}

- Gyan Garcia April 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