Bloomberg interview question

Given a string "AABCCC" make a new string "2A1B3C"

Interview Answers

Anonymous

19 Apr 2017

public class test { public static void main(String[] args) { // TODO Auto-generated method stub String first = "AABCCC"; String newStr = ""; for (int i=0;i

1

Anonymous

29 July 2017

string myS = "AABCCCCCCCCCCC"; string newS; int idx = 0, count = 0; while(idx < myS.size()) { count = 0; char let = myS[idx]; while(idx < myS.size() && let == myS[idx]) { count++; idx++; } newS = newS + to_string(count); newS = newS + let; } cout << newS ;

1

Anonymous

21 Sept 2017

public static void letterFreq(String s) { Map grid = new HashMap(); for(int i = 0; i e :grid.entrySet()) { res+= e.getValue(); res+= e.getKey(); } System.out.print(res); //New String }

Anonymous

21 Sept 2017

public static void letterFreq(String s) { Map grid = new HashMap(); for(int i = 0; i e :grid.entrySet()) { res+= e.getValue(); res+= e.getKey(); } System.out.print(res); //New String }

Anonymous

19 Apr 2017

import java.io.*; import java.util.*; public class HashmapEx { public static void main(String args[]) { String input=new String("AABBBCCZZZAAACCCGGGHHHAAAKKKLLL"); HashMap hm=new HashMap(); char carray[]= input.toCharArray(); for(int i=0;i

1

Anonymous

10 May 2017

const newString = (str) => { let hash = {}, result = ''; for(let i = 0; i < str.length; i++) { if (hash[str[i]]) { hash[str[i]]++ } else { hash[str[i]] = 1; } } for (let prop in hash) { result += `${hash[prop]}${prop}` } return result; } newString('AABCCC')