Twitter Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

Void printFrequency(int arr[], int length)
{
  int current = a[0];
  int count = 1;
  
  for(int i = 1; i < length; i++)
  {
    if(a[i] != current || i == (length - 1))
    {
      cout<<a[i-1]<<":"<<count"\n";
      current = a[i];
      count = 1;
    }
    else
    {
      count++;
    }
  }
}

- Rampal March 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this won't work, try array [1], or [1,1] :-)

- gli00001 November 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

A slight modification to the code can be to remove the "|| i == (length - 1)" part of the if condition, so the last occurring characters in the string are printed out after the for loop instead.

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

function stringrep ( str ) {
  var collection = str.split(' ');
  var seen = {};
  collection.forEach( function ( item ) {
    if ( item in seen ) {
      seen[item]++
    } else {
      seen[item] = 1;
    }
  });
  var resultingCollection = []
  for (var key in seen) {
    resultingCollection.push(key + ":" + seen[key])
  }
  return resultingCollection.join(", ")
}

- Stephen May 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Language - Ruby

def find_freq(str)
  result = {}
  str.split(' ').map do |val|
    (result[val]) ? (result[val] = result[val] + 1) : result[val] = 1
  end
  result
end

- athap June 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In Scala:

val m = str.split('  ').toList.groupBy(x=>x)
val k = m.keySet
k.foreach(x=>print(" " + x+":"+k(x).size))

- http://jasq.org August 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Python:

#!/usr/bin/python
def recurse(list,dic,forbidden):
  if (len(list) == 0):
    print dic
    return
  else:
      try:
        item = int(list.pop())
      except :
        ''' try with hex '''
        item = int(list.pop(),16)
      if item in forbidden:
          recurse(list,dic,forbidden)
          return
      try:
        dic[item] += 1
      except KeyError:
        dic[item] = 1
      recurse(list,dic,forbidden)

if __name__  == "__main__":
  forbidden = [9,11]
  number = "1 0 1 11 19 19 19 12 9 9 11 0x4 0x4"
  result={}
  recurse(number.split(),result,forbidden)

- xsanch February 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void q1(String str) {
        if (str==null || str.length()==0) return;
        String[] s = str.split(" ");
        int[] l = new int[s.length];
        for (int i=0; i<s.length; i++) {
            int h = l[Integer.valueOf(s[i])-1];
            l[Integer.valueOf(s[i])-1] = (h==0?1:h+1);
        }
        for (int i=0; i<l.length; i++) {
            if (l[i]>0)
                System.out.print((i+1)+":"+l[i]+" ");
        }
    }

- george.maggessy April 10, 2013 | 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