ION idea Interview Question Developer Program Engineers

  • ion-idea-interview-questions
    0
    of 0 votes
    8
    Answers

    create an array and remove all the duplicates in the array.no duplicates are allowed in the array.display the contents of the array finally after the duplicates are removed.

    - balaji.paduchuru on May 28, 2012 in India Report Duplicate | Flag
    ION idea Developer Program Engineer Java

Country: India
Interview Type: Written Test


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

Here is an solution to this problem. The code is in C#, it uses a Hashtable for fast lookup of values. A bool/bit array can be used for further optimization.

public static int[] RemoveDuplicates(int[] InputArray)
        {
            //Declare Hashtable for Array Member Duplicate Check
            Hashtable tab = new Hashtable();
            int i, indexPos = 0;

            //Duplicate Check Loop
            for (i = 0; i < InputArray.Length; i++)
            {
                //Check if the Array Member has not been added to Hash Table
                if (!tab.ContainsKey(InputArray[i]))
                {
                    //Add member
                    tab.Add(InputArray[i], 1);
                    InputArray[indexPos] = InputArray[i];
                    indexPos++;
                }
            }

            //Set unused porition of array with -1 as 
            for (i = indexPos; i < InputArray.Length; i++)
            {
                InputArray[i] = -1;                
            }

            return InputArray;
        }

- Irfan Sheikh on May 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

this is a better solution for a array that does not allow duplicates and if any this code removes the duplicates.
import java.io.*;
import java.util.*;
class Array
{
public static void main(String...args)
{
int[] arr1={1,2,2,4,5,4,6,8};
TreeSet <Integer> ts=new TreeSet<Integer>();
for(int i=0;i<arr1.length;i++)
ts.add(new Integer(arr1[i]));
int size=ts.size();
int [] arr=new int[size];
Iterator <Integer>it=ts.iterator();
int j=0;
while(it.hasNext())
{
arr[j]=(Integer)it.next();
j++;
}
for(int x:arr)
{
System.out.println(x);
}
}
}

- balaji on May 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def rmdup_func(arr):
j = len(arr) - 1
i = 0
while i <= j:
for k in range(i):
if arr[i] == arr[k]:
arr[i], arr[j] = arr[j], arr[i]
j -= 1
i -= 1
break
i += 1
return j + 1

arr = [1, 2 , 3, 4, 4, 5, 2]
print arr
e = rmdup_func(arr)
print arr
print arr[:e]

- Anonymous on May 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def rmdup_func(arr):
    j = len(arr) - 1
    i = 0
    while i <= j:
        for k in range(i):
            if arr[i] == arr[k]:
                arr[i], arr[j] = arr[j], arr[i]
                j -= 1
                i -= 1
                break
        i += 1
    return j + 1

arr = [1, 2 , 3, 4, 4, 5, 2]
print arr
e = rmdup_func(arr)
print arr
print arr[:e]

- Mirikle on May 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for (int i = 0; i < inputList.Count - 1; i++)
{
int value = inputList[i];
for (int j = i + 1; j < inputList.Count; j++)
{
if (value == inputList[j])
inputList.RemoveAt(j);
}
}

- hairsh on May 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

create a binary search tree using the source array (ignore duplicates) Once the tree is done, do a in order traversal

- Anonymous on June 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

create a binary search tree using the source array (ignore duplicates) Once the tree is done, do a pre-order traversal

- Anonymous on June 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void dedup(vector<int> &arr)
{
	set<int> uniqueArr;

	for (size_t i = 0; i < arr.size(); i++){
		uniqueArr.insert(arr[i]);
	}

	for (set<int>::iterator it = uniqueArr.begin(); it != uniqueArr.end(); it++){
		cout << *it << ", ";
	}
}

- farzad on June 14, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book walking you through every aspect of getting a job at a top tech company, while focuses on software engineering interviews.

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