Bloomberg Interview Question

1. Write a function to implement the "cat" command in Linux 2. Find the first character that only appears once in the whole string

Interview Answers

Anonymous

Dec 1, 2015

2. Use ASCII characters as the indexex of an array and count the number of the characters in the string

Anonymous

Mar 3, 2016

Apparently you have been taught on a different level of programming than this. The questions are quite basic if you ever worked with Linux or UNIX. Perhaps check job requirements next time. 1) cat concatenates the content of the second file to the content of the first and outputs it (to the screen unless redirected ) open file one until EOF // end of file c = getc file1 copies the content of the second file to the content of the first and outputs it the console print c close file 1 same for file 2 Question 2 The answer given previously would work but is perhaps tricky Simpler (but more time-consuming) would be go through the string from the first character to the last // this needs a for-loop check if the current character appears in the rest of the string // another for loop from the current + 1 position of the string to the end if that is the case BINGO! otheriwise go ahead

Anonymous

Jun 13, 2016

1. Loop through all the characters for the string char array. 2. If you are doing this in Java, use indexOf and lastIndexOf methods. 3. If indexOf and lastIndexOf are same then you have found your first unique char. for(char character : input.toCharArray()) { if(input.indexOf(character) == input.lastIndexOf(character)) { print character; return; } }

Anonymous

Aug 7, 2016

import java.util.*; public class HelloWorld{ public static void main(String []args){ System.out.println(unique("assaiieerrfufuqppp")); } public static char unique(String str) { Map freq = new LinkedHashMap(); for(int i=0; i