Microsoft Interview Question for Interns


Country: United States




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

public class DuplicateFrequency {

	public static void main(String[] args) {
		
		String str = "I am awesomely in Love With ZoomBA!";
		
		char [] strArray = str.toCharArray();
		
		int [] ar = {1,16,2,3,3,4,4,8,6,5,4};
		
		Map<Character, Integer> map = new TreeMap<Character, Integer>();
		
		for (int i=0;  i<strArray.length ; i++) {
			
			if (!map.containsKey(strArray[i]))
			map.put(strArray[i], 1);
			
			else
				map.put(strArray[i],map.get(strArray[i]) +1) ;
		}
		
		map.forEach((k,v) -> System.out.println ("key ="+ k + ", No. of time Repeated "+ v) );
		 
	}

- Anonymous January 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// ZoomBA
s = "I am awesomely in Love With ZoomBA!" 
ms = mset(  s.value )
// produces 
/* 
{ =6, a=2, A=1, !=1, B=1, e=3, h=1, I=1, i=2, l=1, L=1, m=3, n=1, o=4, s=1, t=1, v=1, w=1, W=1, y=1, Z=1} // HashMap
*/

- NoOne January 10, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class DuplicateFrequency {

	public static void main(String[] args) {
		
		String str = "I am awesomely in Love With ZoomBA!";
		
		char [] strArray = str.toCharArray();
		
		int [] ar = {1,16,2,3,3,4,4,8,6,5,4};
		
		Map<Character, Integer> map = new TreeMap<Character, Integer>();
		
		for (int i=0;  i<strArray.length ; i++) {
			
			if (!map.containsKey(strArray[i]))
			map.put(strArray[i], 1);
			
			else
				map.put(strArray[i],map.get(strArray[i]) +1) ;
		}
		
		map.forEach((k,v) -> System.out.println ("key ="+ k + ", No. of time Repeated "+ v) );
		 
	}

- Anas January 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class DuplicateFrequency {

	public static void main(String[] args) {
		
		String str = "I am awesomely in Love With ZoomBA!";
		
		char [] strArray = str.toCharArray();
		
		int [] ar = {1,16,2,3,3,4,4,8,6,5,4};
		
		Map<Character, Integer> map = new TreeMap<Character, Integer>();
		
		for (int i=0;  i<strArray.length ; i++) {
			
			if (!map.containsKey(strArray[i]))
			map.put(strArray[i], 1);
			
			else
				map.put(strArray[i],map.get(strArray[i]) +1) ;
		}
		
		map.forEach((k,v) -> System.out.println ("key ="+ k + ", No. of time Repeated "+ v) );
		 
	}

- thatsanas January 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Pseudo code follows

s = "some string with repeated characters"
map<char, int> m

for each c in some
	m[c]++

for each e in m
	print e.value

- Ashot Madatyan January 13, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

pseudo code below

s = "some string with repeated characters"
map<char, int> m

for each c in some
	m[c]++

for each e in m
	print e.value

- ashot madatyan January 13, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

func printUniqueCharacter(givenString: String) -> (value: Array<Any>, ley: Array<Any>) {

var myCharDict = Dictionary<Character,Int>()

for item in givenString.characters {

if myCharDict[item] != nil {
let value = myCharDict[item]
myCharDict.updateValue(value!+1, forKey: item)
} else {
myCharDict[item] = 1
}
}
let value = Array(myCharDict.values)
let key = Array(myCharDict.keys)

return (value,key)
}

- frustatedALGO January 15, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Void stringStats(string& str) {
	if(str.empty()) {
		return;
}
int histo[(‘z’-’a’ + 1)] = {0};
for(size_t i(0); i < str.size(); ++i) {
	histo[str[i]]++;
}
for(size_t i(0); i < (sizeof(histo)/sizeof(histo[0])); ++i ) {
	if(histo[i] == 0) {
		continue;
}
Std::cout << (‘a’+i) << “ : ” << histo[i] << std::endl();
}
}

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

var listGrouped = myString.GroupBy(x => x,   //the element you want to group by
                                                            (key,    //the element you grouped by
                                                            element  //the new list of strings grouped 
                                                            ) => new
                                                            {
                                                                Key = key,
                                                                Count = element.Count()
                                                            });

            foreach (var item in listGrouped)
            {
                Console.WriteLine("- - - - - - - -");
                Console.WriteLine(item.Key);
                Console.WriteLine(item.Count);
            }

            Console.ReadKey();

It gives this result:

- - - - - - - -
L
1
- - - - - - - -
e
1
- - - - - - - -
o
2
- - - - - - - -
n
1
- - - - - - - -
a
1
- - - - - - - -
r
1
- - - - - - - -
d
1

- LS January 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String text = "text to be tested";
		char[] chars = text.toCharArray();
		Map<Character,Integer> count = new HashMap<>();
		for (char c : chars) {
			if(count.containsKey(c))
			{
				int i = count.get(c);
				count.put(c, ++i);
			}
			else
				count.put(c, 1);
		}
		count.entrySet().stream().forEach(System.out::println  );

- Molham September 03, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/**
   * Javascript Implementation.
   * uniqueCharByCount
   
Given a string, print out all of the unique characters 
and the number of times it appeared in the string

Input:
geeksforgeek
acaaabbbacdddd

Output:
{ g: 2, e: 4, k: 2, s: 1, f: 1, o: 1, r: 1 }
{ a: 5, c: 2, b: 3, d: 4 }
*/


function uniqueCharByCount(str) {
  let charByCountMap = {};
  
  for(let index = 0, length = str.length; index < length; index++) {
    const char = str[index];
    if( !charByCountMap[char] ) {
      charByCountMap[char] = 1;
    } else {
      charByCountMap[char] = charByCountMap[char] + 1;
    }
  }
  console.log(charByCountMap);
}

const str = 'acaaabbbacdddd';
console.log("uniqueCharByCount -> "+str+" \n");
uniqueCharByCount(str);

- Amit Bansal March 07, 2018 | 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