Adobe Interview Question for Software Engineer / Developers






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

Create a max heap taking freq as the comparison point
Now the first 5 elements will be the 5 most common
Time complexity O(nlogn)

- ibnipun10 August 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

how about this

9
7 8
1 2 4 5

how can you get in n(log n) now?

- Anonymous September 22, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

use a max heap of size 5.. you will get the result in nlogn then

- Raman February 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

To prepare a heap of n node it takes O(n) time(with comparator on frequency)
To find the k most occuring strings.Just remove the strings from heap k times.
Every deletion takes log(n) time.So it is n+klogn.
If k i constant then its O(n)...:)

- Anonymous May 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

To prepare a heap of n node it takes O(n) time(with comparator on frequency)
To find the k most occuring strings.Just remove the strings from heap k times.
Every deletion takes log(n) time.So it is n+klogn.
If k i constant then its O(n)...:)

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

Why can't we use weight balanced trees?

- Raju August 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can use Counting Sort to count the occurrence of a particular alphabets which will requires an auxillary array and operation will be done and O(n)time. And then iterate through this auxillary array to get the max occurrence and corresponding alphabet.

- shrawan.raj August 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I would recommend using suffix trees.

- Sid August 16, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char a1[]={'a','b','c','b','c','d','d','b'};
int b[128];
for(int k=0;k<128;k++)
b[k]=0;
for(int i=0;i<strlen(a1);i++)
b[(int)a1[i]]++;
for(i=0;i<128;i++)
{
if(b[i]>0)
cout<<"\n"<<(char)i<<" repeats\t"<<b[i]<<"times";
}
getch();
}

- nipun August 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

wat about "strings"?? a buffer of 128 size wont work in that case..
use hashmap
where key=string and value =count of occurances

- ankit September 07, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

moreover question asks 5 most occuring string, how does this solution takes care of that

- Anonymous September 08, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Lame..

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

can be easily done by taking a
map<string,int> table;

then scan the string and do table[str]++;
in the end print the last 5 values;

map<string, int>::iterator it;
it=table.end();
for(i=0;i<5;i++)
{
cout<<(*it).first;
if(it!=table.begin())it--; else exit;
}

- sweetest September 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use a hashmap and keep the chars as keys ... increment the value as and when u get characters .. this wld run in O(n) time , and will take O(2^32) space maximum (Considering that all unicode characters are considered)

- genius December 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Guys..Why don't you use treemap rather than Hashmap. TreeMap can sort the data automatically using the comparable or comparator interface.

- Newbie December 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think using java classes like treemap or hashmap would not be accepted.
Anyways i too had thought of a hash table sort of structure.
We can design our own hashtable class but ultimately need to have a way to sort the hashtable. In that case it will take O(n) for scanning the elements and putting their counts in hashtable+ O(mlogm) for sorting the hashtable elements. I may b wrng but mlogm could be taken as constant as it depends on number of possible elements as keys

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

I think using java classes like treemap or hashmap would not be accepted.
Anyways i too had thought of a hash table sort of structure.
We can design our own hashtable class but ultimately need to have a way to sort the hashtable. In that case it will take O(n) for scanning the elements and putting their counts in hashtable+ O(mlogm) for sorting the hashtable elements. I may b wrng but mlogm could be taken as constant as it depends on number of possible elements as keys

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

I think using java classes like treemap or hashmap would not be accepted.
Anyways i too had thought of a hash table sort of structure.
We can design our own hashtable class but ultimately need to have a way to sort the hashtable. In that case it will take O(n) for scanning the elements and putting their counts in hashtable+ O(mlogm) for sorting the hashtable elements. I may b wrng but mlogm could be taken as constant as it depends on number of possible elements as keys

- Anshul Zunke February 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think using java classes like treemap or hashmap would not be accepted.
Anyways i too had thought of a hash table sort of structure.
We can design our own hashtable class but ultimately need to have a way to sort the hashtable. In that case it will take O(n) for scanning the elements and putting their counts in hashtable+ O(mlogm) for sorting the hashtable elements. I may b wrng but mlogm could be taken as constant as it depends on number of possible elements as keys

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

I would create two data structures. 1 Hash map, 1 hashset. The hashmap will have key as character and value as count. hashset will work as a placeholder for the items that are already added to hashmap. So
if (!hashset.add("a")) {
i=hashmap.get("a");
i++;hashmap.put("a",i)
}
else
hashmap.put("a",i)

Iterate thru the whole array and calculate the frequency.

- Milind May 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I mean in the else, hashmap.put("a",1);

- Milind May 11, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class CommonOccuring {

public static void main(String[] args) {
String[] arr = { "a", "b", "c", "f", "a", "d", "e", "f", "b", "f", "f" };
Map<String, Integer> map = new HashMap<String, Integer>();
int count = 1;
map.put(arr[0], count);
for (int i = 1; i < arr.length; i++) {
if (map.containsKey(arr[i])) {
map.put(arr[i], map.get(arr[i])+1);
}else{
map.put(arr[i], 1);
}
}
Iterator<Map.Entry<String, Integer>> entries = map.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<String, Integer> entry = entries.next();
System.out.println( entry.getKey() + " " + entry.getValue());
}

}

}

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

public Hashtable countAlphabet (String astring) {

Hashtable table = new Hashtable(); If (astring.length> 4000) return table;

StringBuffer buffer = new StringBuffer(aString);

while (buffer.length() > 0){ String firstChar = buffer.substring(0, 1);

Integer count (Integer) table.get(firstChar);

if (count == null){ count = new Integer (1);

}else{

}

Count = new Integer (count. intvalue() + 1);

table.put(firstChar, count); buffer.delete(0, 1);

} return table;

- Anonymous November 20, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public Hashtable countAlphabet (String astring) {

Hashtable table = new Hashtable(); If (astring.length> 4000) return table;

StringBuffer buffer = new StringBuffer(aString);

while (buffer.length() > 0){ String firstChar = buffer.substring(0, 1);

Integer count (Integer) table.get(firstChar);

if (count == null){ count = new Integer (1);

}else{

}

Count = new Integer (count. intvalue() + 1);

table.put(firstChar, count); buffer.delete(0, 1);

} return table;

- Anonymous November 20, 2022 | 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