String Manipulation Interview Questions
- 0of 0 votes
AnswersFormat a list of strings into a table.
- theeventrodie November 15, 2022 in United States
We have a style guide (for example, lines must be at most 80 characters wide). We have a tool that automatically
formats code to the style guide. One thing it can do is arrange lists of strings into a table. The strings in
each column are left-aligned to be more easily readable. It leaves no holes in the table except after the last
string in the last row (i.e. every cell contains a string, except possibly in the last row). Of course, the
strings remain in the original order.
Example:
W = 70 (characters)
S = [IsAudioBuffer, GetTimestamp, SetTimestamp, GetSampleRate, GetSampleSize, GetNumberOfChannels,
GetNumberOfSamples, GetDataBuffer, GetChannel]
We can format this as follows:
IsAudioBuffer GetTimestamp SetTimestamp GetSampleRate |
GetSampleSize GetNumberOfChannels GetNumberOfSamples GetDataBuffer |
GetChannel |
Given the list of strings, and a maximum number of characters per line, format the table using the maximum
number of columns without violating the line width constraint.| Report Duplicate | Flag | PURGE
Google String Manipulation - 0of 0 votes
AnswersA string can contain only a, b or c. There cannot be 2 consecutive same character. First and the last character cannot be the same. Now given a string with ‘a’, ‘b’, ‘c’ or ‘?’. We need to find the string replacing ‘?’ that satisfy the above conditions. For multiple-answer display lexicographically smallest string. For no answer possible display “Not Possible”.
- anoophky August 31, 2019 in India| Report Duplicate | Flag | PURGE
Directi SDE1 String Manipulation - 0of 0 votes
AnswersString1 -- "aaabb"
- vivekkumarraju May 18, 2019 in United States
String2 -- "aaabbbb"
String3 -- "aaabbb"
These are sample strings. The problem stated that a given string has to be cut in such a fashion that the remaining characters in the string, say a and b have same character count. If not, then the method returns false.
In case the string already has characters with same frequency of occurrence as in case 3, then just return true. Return type can be assumed to be Boolean.
Tried to solve problem using substring() method in java by running a loop over the string, but could not arrive at a solution.| Report Duplicate | Flag | PURGE
VMWare Inc MTS String Manipulation - 2of 2 votes
AnswersVerify if S2 = {5,8,2} is a subset of S1 = {1,5,4,6,8,2} and S3 = {5,8,2,7} is not a subset of S1.
- hadeebataj May 10, 2019 in India| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer String Manipulation - 2of 2 votes
AnswersVerify if the given strings is an anagram.
- hadeebataj May 10, 2019 in India
Ex: Str1: LISTEN, Srt2: SILENT.
Alter the program if there is more than one letter that repeats in any one of the strings.| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer String Manipulation - 0of 0 votes
AnswersGiven two strings, A and B, of equal length, find whether it is possible to cut both strings at a common point such that the first part of A and the second part of B form a palindrome.
- nemishsangani96 March 23, 2019 in India
Extension1. How would you change your solution if the strings could be cut at any point (not just a common point)?
Extension2. Multiple cuts in the strings (substrings to form a palindrome)? Form a palindrome using a substring from both strings. What is its time complexity?| Report Duplicate | Flag | PURGE
Algorithm Coding Computer Science Data Structures Dynamic Programming String Manipulation - 0of 0 votes
AnswersRemove 3 or more consecutive characters from a string, repeat until there are no more.
- kqiann August 17, 2018 in United States
eg.
ABCCCCBBA => ABBBA => AA| Report Duplicate | Flag | PURGE
Bloomberg LP SDE1 String Manipulation - 1of 1 vote
Answers# Given a set of strings, print them in Lexicographic order (dictionary/alphabetical order)
- sarunreddy82 July 11, 2018 in United States
# Example,
# Input:
# “ABCDEF”, “AA”, “BEF”, “A”, “AABB”
# Output:
# “A”, “AA”, “AABB”, “ABCDEF”, “BEF”| Report Duplicate | Flag | PURGE
VMWare Inc String Manipulation - 0of 0 votes
AnswerThis is a word splitter program, I wanted to know the complexity of this program:
- pragramticProgrammer March 08, 2018 in United StatesString s = //"The quick fox jumped over a lazy dog"; "The Java language provides special support for the string " + "concatenation operator ( + ), and for conversion of other " + "objects to strings. String concatenation is implemented " + "through the StringBuilder(or StringBuffer) class and its " + "append method. String conversions are implemented through " + "the method toString, defined by Object and inherited by " + "all classes in Java."; int charLimit = 13; System.out.println("-------------"); char[] chars = s.toCharArray(); boolean endOfString = false; int start = 0; int end = start; while(start < chars.length-1) { int charCount = 0; int lastSpace = 0; while(charCount < charLimit) { if(chars[charCount+start] == ' ') { lastSpace = charCount; } charCount++; if(charCount+start == s.length()) { endOfString = true; break; } } end = endOfString ? s.length() : (lastSpace > 0) ? lastSpace+start : charCount+start; System.out.println(s.substring(start, end)); start = end+1; }
| Report Duplicate | Flag | PURGE
SDE-2 String Manipulation - 0of 0 votes
AnswerWrite a word processor that can do left and right justification for a sample input of string type.
- annu025 March 07, 2018 in United States
Here is an example:
This is a sample.This is a sample.This is a sample.
This is a sample.This is a sample.This is a sample.This is a sample.
Additional details:
* The left margin is 5 units.
* The right margin is 75 units.
* The input string is a single-spaced collection of words and punctuation.
* If the length of the word exceeds the right margin, then we must not break the word. Instead, we must print it on the next line and justify the existing line by adding more spaces to the middle of the line.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer String Manipulation - 0of 0 votes
AnswersIt was asked in Chargebee off campus interview. Needed solution for this problem in java
- psribalaji12 February 08, 2018 in India
Given a string say s and k denotes the number of commas and the output should be like when you insert the comma in the string at different places and find the maximum number.
Test case 1
say s = 999 and k = 1 so the choice would be 9,99 or 99,9 in either case the maximum number is 99
Test case 2
say s=999 and k =2 so the choice will be like 9,9,9 so output will be 9
Test case 3
say s = 857 and k = 1 the choice would be 85,7 or 8,57 so the output will be like 85| Report Duplicate | Flag | PURGE
StartUp Java Developer Arrays Brain Storming String Manipulation - 2of 2 votes
AnswersReverse this string 1+2*3-20. Note: 20 must be retained as is.
- annu025 September 21, 2017 in United States
Expected output: 20-3*2+1| Report Duplicate | Flag | PURGE
String Manipulation - 0of 0 votes
AnswersPerform left and right shift on string
- purva7 July 24, 2017 in United States| Report Duplicate | Flag | PURGE
GE (General Electric) Software Developer String Manipulation - 2of 2 votes
AnswersReverse the words in string eg. 'The Sky is Blue'. then print 'Blue is Sky The'.
- purva7 July 24, 2017 in United States| Report Duplicate | Flag | PURGE
Expedia Software Developer String Manipulation - 4of 4 votes
AnswersYou are given set of strings, You have return anagrams subsets from it. An anagram set is that one where every string is an anagram of another string. If the subset contains only one string, don't include that in the result.
- sonesh May 11, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm String Manipulation - 0of 0 votes
AnswersRegex matching algorithms
- sonesh May 08, 2017 in United States
You will be given a string and a pattern string consisting of only '*','?', and small letters. You have to return tree or false based upon the comparisons.
? repersent one char.
* means zero or n number of char for any positive n.
Example
abc, a?c : true
abc, a*?c : true
abc, * : true
abc, ?c : false| Report Duplicate | Flag | PURGE
Two Sigma Software Engineer / Developer String Manipulation - 2of 2 votes
AnswersGiven an input string and a dictionary of words, find out if the input string can be segmented into a space-separated sequence of dictionary words.
- Anon April 29, 2017 in United States
Ex: "bedbathandbeyond" would be "bed bath and beyond" which are all dictionary words.| Report Duplicate | Flag | PURGE
Facebook Software Engineer String Manipulation - 0of 0 votes
AnswersYou are given two string (like two statements). You have to remove all the words of second string from first string and print the remaining first string. Please maintain the order of the remaining words from the first string. You will be only removing the first word, not all occurrence of a word.
- sonesh April 18, 2017 in United States
Example: Str1 = "A Statement is a Statement", Str2 = "Statement a"
Output: "A is Statement"| Report Duplicate | Flag | PURGE
Expedia Software Engineer / Developer String Manipulation - 0of 0 votes
AnswersYou are given an array of words. from each word, you make a chain, in that, you remove one char at a time and you remove that char only when the remaining word is present in the input array.
- sonesh April 18, 2017 in United States
For Example, if the input is {a, b, ab, ac, aba}
then the possible chains are
from 'a', there is no chain, the chain it 'a' itself (of length 1)
similarly, from 'b', the chain length is 1 one (length is defined by the number of words in the chain)
now from 'ab', there are two possibilities which are ({ab -> b when you remove a},{ab -> a when you remove b}). So the max length is 2 here
now from 'ac', we only have one possibility which is ({ac -> a when we remove c}), because, when we remove 'a', we left with 'c' which is not present in the input.
Now, you have to find the length of the biggest such chain.
Input: array of words
Output: length of the biggest such chain.| Report Duplicate | Flag | PURGE
Two Sigma Software Engineer / Developer Algorithm String Manipulation - 1of 1 vote
AnswersGiven an input string "aabbccba", find the shortest substring from the alphabet "abc".
- shalu January 25, 2017 in United States
In the above example, there are these substrings "aabbc", "aabbcc", "ccba" and "cba". However the shortest substring that contains all the characters in the alphabet is "cba", so "cba" must be the output.
Output doesnt need to maintain the ordering as in the alphabet.
Other examples:
input = "abbcac", alphabet="abc" Output : shortest substring = "bca".| Report Duplicate | Flag | PURGE
Facebook Software Engineer String Manipulation - -5of 5 votes
Answersna
- Anonymous January 10, 2017 in -| Report Duplicate | Flag | PURGE
String Manipulation - 0of 0 votes
AnswersGiven a string, print out all of the unique characters and the number of times it appeared in the string
- mh4wt@virginia.edu January 09, 2017 in United States| Report Duplicate | Flag | PURGE
Microsoft Intern Java String Manipulation - 0of 0 votes
AnswersYou have a string aaabbdcccccf, transform it the following way => a3b2d1c5f1
- Blank October 29, 2016 in United States for Infrastructure
ie: aabbaa -> a2b2a2 not a4b2| Report Duplicate | Flag | PURGE
Salesforce Intern String Manipulation - 4of 4 votes
AnswersYou are given a scrambled input sentence. Each word is scrambled independently, and the results are concatenated. So:
- merlinme October 25, 2016
'hello to the world'
might become:
'elhloothtedrowl'
You have a dictionary with all words in it. Unscramble the sentence.| Report Duplicate | Flag | PURGE
Google Site Reliability Engineer String Manipulation - 1of 1 vote
AnswersProgramming Challenge Description:
- abhinav.thegame October 17, 2016 in United States
Develop a service to help a client quickly find a manager who can resolve the conflict between two employees. When there is a conflict between two employees, the closest common manager should help resolve the conflict. The developers plan to test the service by providing an example reporting hierarchy to enable the identification of the closest common manager for two employees. Your goal is to develop an algorithm for IBM to efficiently perform this task. To keep things simple, they just use a single relationship "isManagerOf" between any two employees. For example, consider a reporting structure represented as a set of triples:
Tom isManagerOf Mary
Mary isManagerOf Bob
Mary isManagerOf Sam
Bob isManagerOf John
Sam isManagerOf Pete
Sam isManagerOf Katie
The manager who should resolve the conflict between Bob and Mary is Tom(Mary's manager). The manager who should resolve the conflict between Pete and Katie is Sam(both employees' manager). The manager who should resolve the conflict between Bob and Pete is Mary(Bob's manager and Pete's manager's manager).
Assumptions:
There will be at least one isManagerOf relationship.
There can be a maximum of 15 team member to a single manager
No cross management would exist i.e., a person can have only one manager
There can be a maximum of 100 levels of manager relationships in the corporation
Input:
R1,R2,R3,R4...Rn,Person1,Person2 R1...Rn - A comma separated list of "isManagerOf" relationships. Each relationship being represented by an arrow "Manager->Person". Person1,Person2 - The name of the two employee that have conflict
Output:
The name of the manager who can resolve the conflict Note: Please be prepared to provide a video follow-up response to describe your approach to this exercise.
Test 1:
Test Input
Frank->Mary,Mary->Sam,Mary->Bob,Sam->Katie,Sam->Pete,Bob->John,Bob,Katie
Expected Output
Mary
Test 2:
Test Input
Sam->Pete,Pete->Nancy,Sam->Katie,Mary->Bob,Frank->Mary,Mary->Sam,Bob->John,Sam,John
Expected Output
Mary| Report Duplicate | Flag | PURGE
IBM Software Engineer / Developer Coding Java Python String Manipulation - 3of 3 votes
AnswersGiven an input string and ordering string, need to return true if the ordering string is present in Input string.
- ranjith2jeeth August 04, 2016 in United States
input = "hello world!"
ordering = "hlo!"
result = FALSE (all Ls are not before all Os)
input = "hello world!"
ordering = "!od"
result = FALSE (the input has '!' coming after 'o' and after 'd', but the pattern needs it to come before 'o' and 'd')
input = "hello world!"
ordering = "he!"
result = TRUE
input = "aaaabbbcccc"
ordering = "ac"
result = TRUE| Report Duplicate | Flag | PURGE
Uber Software Engineer String Manipulation - 0of 0 votes
AnswersList of string that represent class names in CamelCaseNotation.
- lavankumarmuvalla July 07, 2016 in United States
Write a function that given a List and a pattern returns the matching elements.
['HelloMars', 'HelloWorld', 'HelloWorldMars', 'HiHo']
H -> [HelloMars, HelloWorld, HelloWorldMars, HiHo]
HW -> [HelloWorld, HelloWorldMars]
Ho -> []
HeWorM -> [HelloWorldMars]| Report Duplicate | Flag | PURGE
Google String Manipulation - 1of 1 vote
Answersprint all the characters present in the given string only once in a reverse order. Time & Space complexity should not be more than O(N).
- anonymous May 31, 2016 in United States
e.g.
1)Given a string aabdceaaabbbcd
the output should be - dcbae
2)Sample String - aaaabbcddddccbbdaaeee
Output - eadbc
3)I/P - aaafffcccddaabbeeddhhhaaabbccddaaaa
O/P - adcbhef
Answer :
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;
public class StringQAmazon {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String inputStr = sc.nextLine();
System.out.println(stringManipulation(inputStr));
}
static String stringManipulation(String str) {
if(str.isEmpty())
return "";
else if(str.length()==1)
return str;
else {
str.toLowerCase();
StringBuilder strBuilder = new StringBuilder();
strBuilder.append(str);
strBuilder.reverse();
Set<Character> set = new LinkedHashSet<Character>();
for(int i =0; i<strBuilder.length(); i++){
set.add(strBuilder.charAt(i));
}
Iterator<Character> iter = set.iterator();
strBuilder=new StringBuilder();
while(iter.hasNext()){
strBuilder.append(iter.next());
}
return strBuilder.toString();
}
//return null;
}
}| Report Duplicate | Flag | PURGE
Amazon SDE-2 String Manipulation - 0of 0 votes
AnswersGiven an api which returns an array of chemical names and an array of chemical symbols, display the chemical names with their symbol surrounded by square brackets:
- abcpiipii May 25, 2016 in United States
Ex:
Chemicals array: ['Amazon', 'Microsoft', 'Google']
Symbols: ['I', 'Am', 'cro', 'Na', 'le', 'abc']
Output:
[Am]azon, Mi[cro]soft, Goog[le]
If the chemical string matches more than one symbol, then choose the one with longest length. (ex. 'Microsoft' matches 'i' and 'cro')
My solution:
(I sorted the symbols array in descending order of length and ran loop over chemicals array to find a symbol match(using indexOf in javascript) which worked. But I din't make it through the interview, I am guessing my solution was O(n2) and they expected an efficient algorithm.| Report Duplicate | Flag | PURGE
Uber Software Engineer Algorithm String Manipulation - 3of 3 votes
AnswersGiven a string e.g. ABCDAABCD. Shuffle he string so that no two smilar letters together.
- rajnikant12345 March 13, 2016 in India for Office
E.g. AABC can be shuffled as ABAC.| Report Duplicate | Flag | PURGE
Microsoft SDE-2 String Manipulation