Salesforce Interview Question for Interns


Team: Infrastructure
Country: United States
Interview Type: Phone Interview




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

// ZoomBA
def sales_force( s ){
  len = #|s|
  if ( len == 0 ) return ''
  #(last,cnt, ret) = fold ( [1:len] , [s[0], 1, '' ] ) -> {
    #(prev, count, res ) = $.prev
    if ( prev != s[$.item] ){
        res += ( str( prev ) + count )
        count = 1 
    }else{
      count +=1 
    }
    [ s[$.item] , count , res ]
  }
  ret +=  ( str( last ) + cnt )
}
s = 'aaabbdcccccf'
println( sales_force( s ) )

- NoOne October 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Can anyone do this in Javascript?

- LearningCode November 18, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is my javascript solution

let x = 'aaabbdcccccf'
let ans = ''

x = x.split('')
let i = 1;
let cur = x[0];
let count = 1;
while (i < x.length){
  if(x[i] === cur){
    count+=1
  }else{
    ans += cur+count
    count = 1
    cur=x[i]
  }
  
  i++
}

ans += cur+count

console.log(ans)

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

///////////////////////////////////////////////////////////////
// Author - Prakhar Pratyush
// IIT Roorkee, Final Year
// er.prakhar2b@gmail.com
//
////////////////////////////////////////////////////////////////

#include <bits/stdc++.h>

using namespace std;

int main(){
	string s;
	cin>>s;

	int n = s.length();
	int count = 1;

	cout<<s[0];

	for(int i=1;i<n;i++){
		if(s[i] != s[i-1])
		{
			cout<<count<<s[i];
			count = 1;
		}
		else if(s[i]==s[i-1]) count++;
	}

	cout<<count<<"\n";

	return 0;
}

- Prakhar Pratyush October 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void stringpatterns(string s)
        {

            string newstr = "";

            int count = 1,i=1;

            for (int j = 0; j < s.Length; j++)
            {
                if (i<s.Length && s[i] == s[i - 1])
                {
                    count++;
                }
                else
                {
                    newstr = newstr + s[i - 1] + count;
                    count = 1;
                }
                i++;
            }

            Console.WriteLine("Output: " + newstr);
        }

- brahmi.mamillapalli9 November 01, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <stdlib.h>
int main()
{
char str[50];
printf("Enter a string \n");
gets(str);

int i;
int c=1;
printf("%c",str[0]);
for(i=1;i<=strlen(str);i++)
{
if (str[i]!=str[i-1])
{

printf("%d",c);
printf("%c",str[i]);
c=1;
}
else if(str[i]==str[i-1])
{
c++;
}
}

}

- Ankit Kumar November 02, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char str[50];
  printf("Enter a string \n");
  gets(str);

  int i;
  int c=1;
  printf("%c",str[0]);
  for(i=1;i<=strlen(str);i++)
  {
      if (str[i]!=str[i-1])
       {

        printf("%d",c);
        printf("%c",str[i]);
         c=1;
       }
       else if(str[i]==str[i-1])
       {
           c++;
       }



  }

}

- Ankit Kumar November 02, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void stringPattern(String str){
         char[] letters = str.toLowerCase().toCharArray();
         int counter =1;
         StringBuilder sb = new StringBuilder();
         System.out.println("Print length:"+letters.length);
         for(int i=0;i<letters.length;i++){
             if(letters.length == i+1){
                sb.append(letters[i]).append(counter);
                 break;
             }
             if(letters[i]==letters[i+1]){
                 counter=counter+1;
             }else{
                 sb.append(letters[i]).append(counter);
                 counter=1;
             }
         }
         System.out.println(sb);
     }

- Mahesh November 06, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void stringPattern(String str){
         char[] letters = str.toLowerCase().toCharArray();
         int counter =1;
         StringBuilder sb = new StringBuilder();
         System.out.println("Print length:"+letters.length);
         for(int i=0;i<letters.length;i++){
             if(letters.length == i+1){
                sb.append(letters[i]).append(counter);
                 break;
             }
             if(letters[i]==letters[i+1]){
                 counter=counter+1;
             }else{
                 sb.append(letters[i]).append(counter);
                 counter=1;
             }
         }
         System.out.println(sb);
     }

- Mahesh November 06, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void stringPattern(String str){
char[] letters = str.toLowerCase().toCharArray();
int counter =1;
StringBuilder sb = new StringBuilder();
System.out.println("Print length:"+letters.length);
for(int i=0;i<letters.length;i++){
if(letters.length == i+1){
sb.append(letters[i]).append(counter);
break;
}
if(letters[i]==letters[i+1]){
counter=counter+1;
}else{
sb.append(letters[i]).append(counter);
counter=1;
}
}
System.out.println(sb);
}

- Mahesh November 06, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

'''
if original string length is less than the return string
return the original string
'''
def compress(inp_str):
    if len(inp_str) < 2:
        return inp_str
    return_str = ""
    count,prev = 1,0
    for curr in range(1,len(inp_str)):
        if inp_str[prev] == inp_str[curr]:
            count = count + 1
        else:
            return_str += inp_str[prev] + str(count)
            count = 1
        prev = curr
    #attending the last unit test case
    return_str += inp_str[-1] + str(count)
    return return_str if len(return_str) <= len(inp_str) else inp_str

assert compress("aaabbdcccccf") == "a3b2d1c5f1"
assert compress("ab") == "ab"

- pranav garg November 12, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

'''
if original string length is less than the return string
return the original string
'''
def compress(inp_str):
    if len(inp_str) < 2:
        return inp_str
    return_str = ""
    count,prev = 1,0
    for curr in range(1,len(inp_str)):
        if inp_str[prev] == inp_str[curr]:
            count = count + 1
        else:
            return_str += inp_str[prev] + str(count)
            count = 1
        prev = curr
    #attending the last unit test case
    return_str += inp_str[-1] + str(count)
    return return_str if len(return_str) <= len(inp_str) else inp_str

assert compress("aaabbdcccccf") == "a3b2d1c5f1"
assert compress("ab") == "ab"

- pranav garg November 12, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

C# solution

Console.WriteLine("Enter the string");
            string s = Console.ReadLine();
            int c=0,flag=0,j=0;
            for (int i = 0; i < s.Length;)
            {
                c = 0;
                for (j = 0; j < s.Length; j++)
                {
                    
                    if (s[i] == s[j])
                    {
                        flag = 1;
                        c++;
                    }
                    else if(flag==1)
                    {
                        Console.Write("{0}{1}", s[i], c);
                        i = j;
                        flag = 0;                    
                        
                        break;
                    }
                }
                if (j == s.Length)
                {
                    Console.Write("{0}{1}", s[i], c);
                    break;
                }
           }

- jeyaseelan November 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

C# Solution

public static string EncodeString(string input)
        {
            string res = string.Empty;
            int count = 0;

            for (int i = 0; i < input.Length; i++)
            {
                count++;
                if (i == input.Length - 1 || input[i] != input[i + 1])
                {
                    res += $"{input[i]}{count}";
                    count = 0;
                }
            }
            return res;
        }

- Sergey Dorofeev November 23, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def process_str(a):
new_str = ""
char_ctr = 0
for index, char in enumerate(a):
if new_str == "":
new_str += char
char_ctr += 1
continue
elif new_str[-1] == char:
char_ctr += 1
if index == len(a) - 1:
new_str += str(char_ctr)
continue
else:
new_str += str(char_ctr) + char
char_ctr = 1
if index == len(a) - 1:
new_str += str(char_ctr)
continue
return new_str


if __name__ == "__main__":
a = "aaaffffeeesssw"
print a
print process_str(a)

- Ravibala Kakatkar November 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

string inputString;
int runningLength = 0; // current running length of the prev char
char prevChar = '$'; //<-- store the char at prev index

int countRunningLength(String inputString){

and

Scanner sc = new Scanner(System.in);

and

inputString = sc.nextLine();
int length = inputString.length();

for(int indx = 0; indx < length; indx++){
if(inputString.charAt(indx) == prevChar){
runningLength++;
} else {
if(runningLength > 0){
System.out.print(prevChar + runningLength);
}
runningLength = 0;
prevChar = inputString.charAt(indx);
}
}

if(runningLength > 0){
System.out.print(prevChar + runningLength);
}

}

- Nguyen Tuong Van December 05, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript">


    function convertString(gString){
        var arrStr = gString.split("");
        var currentStr = 0;
        var count = 0;
        var result = '';
        var first = true;
      for ( var i = 0; i < arrStr.length; i++){
          if(arrStr[currentStr] == arrStr[i]){
              count ++;
          }else {
              result += arrStr[currentStr] + count;
              currentStr = i;
              count = 1;
          }        
    }
    result += arrStr[currentStr] + count;
        document.getElementById("op").innerHTML = result;
    };

    function countString(){
      var gString = document.getElementById("string").value;

      convertString(gString);
    }
  </script>
</head>
<body>
  <h2>String tranform</h2>
  <input type="text" id="string"/>
  <button onclick="countString()">submit</button>
  <p> Text converted: <span id="op"></span></p>
</body>
</html>

- K.A.Mathan December 15, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<string.h>
using namespace std;

int main(){
string a;
int temp;
char c;


cout<<"enter string\n";
getline(cin,a);

for(int i=0;a[i]!='\0';){
temp =0;
c = a[i];
while(c==a[i])
{
temp++;
i++;
}
cout<<c<<temp;
}

return 0;
}

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

#include<iostream>
#include<string.h>
using namespace std;

int main(){
	  string a;
	  int temp;
	  char c;
	  
	  
	  cout<<"enter string\n";
	  getline(cin,a);
	  
	  for(int i=0;a[i]!='\0';){
	  	temp =0;
	  		c = a[i];
	  		while(c==a[i])
	  		  {
	  		  	temp++;
	  		  	i++;
				}
				cout<<c<<temp;
	  }

	return 0;

}

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

#include<iostream>
#include<string.h>
using namespace std;

int main(){
	  string a;
	  int temp;
	  char c;
	  
	  
	  cout<<"enter string\n";
	  getline(cin,a);
	  
	  for(int i=0;a[i]!='\0';){
	  	temp =0;
	  		c = a[i];
	  		while(c==a[i])
	  		  {
	  		  	temp++;
	  		  	i++;
				}
				cout<<c<<temp;
	  }

	return 0;

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

Objective-C

-(void)countCharOccurence:(NSString *)str {
    NSString *current = [str substringWithRange:NSMakeRange(0, 1)];
    
    int count = 1;
    
    for(int i = 1; i<str.length; i++) {
        if (current == [str substringWithRange:NSMakeRange(i, 1)]) {
            count++;
        } else {
            printf("%s%i", [current UTF8String], count);
            current = [str substringWithRange:NSMakeRange(i, 1)];
            count = 1;
        }
    }
    printf("%s%i", [current UTF8String], count);
}

- Atalyk.Akash@nu.edu.kz January 31, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private static StringBuffer charCountPattern(String string) {
		int len = string.length();
		StringBuffer sb = new StringBuffer();
		for (int j = 0; j <= len - 1; j++) {
			int count = 1, k = j + 1;

			sb.append(string.charAt(j));
			if (j == (len - 1)) {
				break;
			} else {
				while ((k < len) && (string.charAt(j) == string.charAt(k))) {
					count++;
					k++;
				}
				j = k - 1;
				sb.append(count);
				if (k == len)
					break;
			}
		}
		char lastChar = sb.charAt(sb.length() - 1);
		if (!Character.toString(lastChar).matches("[0-9]+")) {
			sb.append("1");
			return sb;
		}
		return sb;
	}

- o February 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private static StringBuffer charCountPattern(String string) {
int len = string.length();
StringBuffer sb = new StringBuffer();
for (int j = 0; j <= len - 1; j++) {
int count = 1, k = j + 1;

sb.append(string.charAt(j));
if (j == (len - 1)) {
break;
} else {
while ((k < len) && (string.charAt(j) == string.charAt(k))) {
count++;
k++;
}
j = k - 1;
sb.append(count);
if (k == len)
break;
}
}
char lastChar = sb.charAt(sb.length() - 1);
if (!Character.toString(lastChar).matches("[0-9]+")) {
sb.append("1");
return sb;
}
return sb;
}

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

String formatStringOccurences(String s) {
		char[] arr = s.toCharArray();
		StringBuffer modStr = new StringBuffer();
		Map<Character, Integer> hm = new HashMap<>();
		for (char c : arr) {
			if (hm.containsKey(c)) {
				hm.put(c, hm.get(c) + 1);
			} else {
				hm.put(c, 1);
			}
		}
		for (char c : hm.keySet()) {
			modStr.append(c);
			modStr.append(hm.get(c));
		}
		return modStr.toString();
	}

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

public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String input = scan.nextLine();
		char c = input.charAt(0);
		int count = 1;
		for(int i = 1; i <= input.length(); i++) {
			while(i < input.length() && c == input.charAt(i)) {
				count++;
				i++;
			}
			System.out.print(c + String.valueOf(count));
			if(i < input.length()) {
				c = input.charAt(i);
				count = 1;
			}
		}
		
		scan.close();
	}

- Ishwar Khatri June 02, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

C# Solution

public static string AlphabetCounter(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return string.Empty;
            }
            char previousChar = char.MinValue;
            var counter = 0;
            var stringOutput = new StringBuilder();
            for (int i = 0; i < input.Length; i++)
            {
                if (input[i] != previousChar)
                {
                    counter = 1;
                    previousChar = input[i];
                    stringOutput.Append(input[i]).Append(counter);
                }
                else
                {
                    stringOutput = stringOutput.Remove(stringOutput.Length - 1, 1);
                    counter++;
                    stringOutput.Append(counter);
                }
            }
            Console.WriteLine(stringOutput);
            return stringOutput.ToString();
        }

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

void convert_string(string str) {
    int start = 0;
    int current = start;
    if(!str.length()) {
        return;
    }
    stringstream ss;
    while(current < str.length()) {
        if(str[start] != str[current]) {
            ss << str[start];
            ss <<(current-start);
            start = current;
        }
        current++;
    }
    ss << str[start];
    ss<< current-start;
    cout << ss.str();
}

- ali.kheam July 09, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
	String inputStr = "aaabbccc";
	StringBuilder outStr = new StringBuilder();
	char[] arr = inputStr.toCharArray();
	int count = 0;
	int i = 0;

	while(i < arr.length)  {
		if(i == 0) {
			count++;
		} else {
			if(arr[i] == arr[i-1]) {
				count++;
			} else {
				outputStr.append(arr[i-1]+""+count);
			}
		}
	}	
	outputStr.append(arr[arr.length-1]+""+count);
	System.out.println(outputStr);
}

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

public static void main(String[] args) {
		String str ="aaabbdcccccf";
		int size = str.length();
		char[] chararr = str.toCharArray();
		StringBuilder sb = new StringBuilder();
		int counter = 1;
		for(int i=0; i< size; i++){
			//check if the current element & next element value are same
			if(i+1 <size){
							if(chararr[i] == chararr[i+1]){
								counter = counter +1;
							}else{
								//not equal
								sb.append(str.charAt(i));
								sb.append(counter);
								counter = 1;
							}
			}else{
				sb.append(str.charAt(i));
				sb.append(counter);
			}
		}
		System.out.println(sb.toString());
		
	}

- Kishore Chaganti September 05, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
		String str ="aaabbdcccccf";
		int size = str.length();
		char[] chararr = str.toCharArray();
		StringBuilder sb = new StringBuilder();
		int counter = 1;
		for(int i=0; i< size; i++){
			if(i+1 <size){
							if(chararr[i] == chararr[i+1]){
								counter = counter +1;
							}else{
								//not equal
								sb.append(str.charAt(i));
								sb.append(counter);
								counter = 1;
							}
			}else{
				sb.append(str.charAt(i));
				sb.append(counter);
			}
		}
		System.out.println(sb.toString());
		
	}

- Kishore Chaganti September 05, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Python

def check(s1):
	len1 = len(s1)
	s2 = ''
	count = 1
	Flag = False
	for i in range (0,len1):
		if i <= len1-2:
			
			if s1[i] == s1[i+1]:
				count += 1
				if i+1 == len1-1:
					count = str(count)
					s2 = s2 + s1[i] +count
				
			else:
				count = str(count)
				s2 = s2+s1[i]+count
				count = 1
				Flag = True
		else:
			if s1[len1-1] != s1[len1-2]:
				s2 = s2 + s1[len1-1]+'1'


	if Flag == False:
		count = str(count)
		s2 = s1[0] + count

	print s2

- Deepali Agarwal February 08, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def check(s1):
	len1 = len(s1)
	s2 = ''
	count = 1
	Flag = False
	for i in range (0,len1):
		if i <= len1-2:
			
			if s1[i] == s1[i+1]:
				count += 1
				if i+1 == len1-1:
					count = str(count)
					s2 = s2 + s1[i] +count
				
			else:
				count = str(count)
				s2 = s2+s1[i]+count
				count = 1
				Flag = True
		else:
			if s1[len1-1] != s1[len1-2]:
				s2 = s2 + s1[len1-1]+'1'


	if Flag == False:
		count = str(count)
		s2 = s1[0] + count

	print s2

- Deepali Agarwal February 08, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/**
   * Javascript Implementation.
   * charByCount
   
You have a string aaabbdcccccf, transform it the following way => a3b2d1c5f1 
ie: aabbaa -> a2b2a2 not a4b2

Input:
acaaabbbacdddd
aaabbdcccccf
aabbaa

Output:
a1c1a3b3a1c1d4
a3b2d1c5f1
a2b2a2

*/


function charByCount(str) {
  let result = "";
  let lastChar = str[0];
  let counter = 0;
  for(let index = 0, length = str.length; index < length; index++) {
    const char = str[index];
    if(char === lastChar) {
      counter++;
    } else {
      result = result + lastChar + counter;
      counter = 1; //reset the counter
      lastChar = char; //reset the lastChar
    }
    // if str is ending with same last chars e.g. 'acaaabbbacdddd'
    if(index === str.length - 1 && counter > 0) {
      result = result +  lastChar + counter;
    }
  }
  console.log(result);
}

const str1 = 'acaaabbbacdddd'; // a1c1a3b3a1c1
const str2 = 'aaabbdcccccf'; // a3b2d1c5
const str3 = 'aabbaa'; // a2b2

console.log("charByCount -> "+str1);
charByCount(str1);

console.log("charByCount -> "+str2);
charByCount(str2);

console.log("charByCount -> "+str3);
charByCount(str3);

- Amit Bansal March 07, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) throws IOException {
    	String example = "aaadddddddddddddbbbbbccf";
    	List<Character> visitedLetters = new ArrayList<Character>();
    	for(int i=0;i<example.length();i++)
    	{
    		if(!visitedLetters.contains(example.charAt(i)))
    		{
    		int counter=0;
    		for(int j=1;j<example.length();j++)
    		{
    			if(example.charAt(i) == example.charAt(j))
    			{
    				counter++;
    			}
    		}
    		visitedLetters.add(example.charAt(i));
    		
    			System.out.print(String.valueOf(example.charAt(i))+counter);
    		}
    	}
    }

- Ankita Patil January 22, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) throws IOException {
    	String example = "aaadddddddddddddbbbbbccf";
    	List<Character> visitedLetters = new ArrayList<Character>();
    	for(int i=0;i<example.length();i++)
    	{
    		if(!visitedLetters.contains(example.charAt(i)))
    		{
    		int counter=0;
    		for(int j=1;j<example.length();j++)
    		{
    			if(example.charAt(i) == example.charAt(j))
    			{
    				counter++;
    			}
    		}
    		visitedLetters.add(example.charAt(i));
    		
    			System.out.print(String.valueOf(example.charAt(i))+counter);
    		}
    	}
    }

- Ankita Patil January 22, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def char_counter(string):
    if len(string) == 0:
        return string
    if len(string) == 1:
        return string + "1"
    
    ret = ""
    
    prev = string[0]
    count = 1

    for i in range(1, len(string)):
        char = string[i]
        if char == prev:
            count += 1
        else:
            ret += prev + str(count)
            count = 1
            prev = char
    ret += prev + str(count)
    return ret

#print (char_counter("a"))
assert char_counter("ab") == "a1b1"

- Python solution February 07, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String stringnum(String str){
char[] c = str.toCharArray();
int[] count = new int[26];

for (char c1: c){
int i = (int) c1 - 'a';
count[i]++;
}
System.out.println(Arrays.toString(count));

StringBuilder result = new StringBuilder();
for (int i= 0; i<26;i++){
if (count[i] > 0) {
int j = i + 'a';
char c3 = (char) j;
result.append(c3);
result.append(count[i]);
}
}
System.out.println(result.toString());
return result.toString();
}

- Manish Pandit May 13, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String stringnum(String str){
char[] c = str.toCharArray();
int[] count = new int[26];

for (char c1: c){
int i = (int) c1 - 'a';
count[i]++;
}
System.out.println(Arrays.toString(count));

StringBuilder result = new StringBuilder();
for (int i= 0; i<26;i++){
if (count[i] > 0) {
int j = i + 'a';
char c3 = (char) j;
result.append(c3);
result.append(count[i]);
}
}
System.out.println(result.toString());
return result.toString();
}

- Manish Pandit May 13, 2020 | 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