VMWare Inc Interview Question

• 1
of 1 vote

Country: United States
Interview Type: Phone Interview

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

``list.sort(Comparator.naturalOrder())``

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

We can use Java inbuilt function compateTo(comparableString) and achieve this with n2 complexity. Below is a sample code snippet.

``````for(int i=0;i<=s.length-2;i++)
{
System.out.println(s[i]);
for(int j=i+1;j<=s.length-1;j++)
{

if(s[i].compareTo(s[j])>0)
{
String temp = s[j];
s[j]=s[i];
s[i]=temp;
}
}
}``````

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

Java inbuilt function compareTo will work but with n2 complexity

for(int i=0;i<=s.length-2;i++)
{
System.out.println(s[i]);
for(int j=i+1;j<=s.length-1;j++)
{

if(s[i].compareTo(s[j])>0)
{
String temp = s[j];
s[j]=s[i];
s[i]=temp;
}
}
}

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

Method 1: use general sorting algorithm Complexity: O(nlogn)
Method 2: use Trie data structures O(n)

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

Can you someone help me how to get this using Trie DS. I have given all the above solutions but interviewer asked me to implement using Trie DS.

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

Can anyone one help me solve this using Trie DS. I have given all the above solutions but interviewer asked me to implement using Trie.

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

import java.util.Arrays;

public class StringSort {

public static void main(String[] args) {

String abc[]= {"ABCDEF","A","BEF","AABB","AA"};
Arrays.sort(abc);
for(int i=0;i<abc.length;i++)
{
System.out.println(abc[i]);
}

}

}

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

``````public class PrintInLexicographicOrder {
public static void main(String[] args) {
List<String> stringList = Arrays.asList( new String[]{"ABCDEF", "AA", "BEF", "A", "AABB"} );
Set<String> stringSet = new HashSet<>( stringList );
String s[] = stringSet.toArray( new String[stringSet.size()] );
for (int i = 0; i < s.length; i++) {
for (int j = i + 1; j < s.length; j++) {
if (s[i].compareTo( s[j] ) > 0) {
String temp = s[j];
s[j] = s[i];
s[i] = temp;
}
}
}
System.out.println("LEXICOGRAPHIC ORDER: -> "+ Arrays.toString( s ) );
}
}``````

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

def laxilogical(string):
''' Print string in Laxilogical Order'''
string.sort()
return string

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

For this problem, we have to first define a string which will hold all the alphabets in the order of "a" to "z", we will store all the characters in a hashmap and then we will sort the array of strings according to the order in which the string is defined and then print the result.

Implementation:

#include<bits/stdc++.h>
using namespace std;
map<char, int> h;
bool compare(string x, string y){
for(int i = 0; i < min(x.size(), y.size()); i++){
if(h[x[i]] == h[y[i]])
continue;
return h[x[i]] < h[y[i]];
}
return x.size() < y.size();
}
int main()
{
string str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vector<string> v = { "ABCDEF", "AA", "BEF",
"A", "AABB" };
for(int i = 0; i < str.length(); i++)
h[str[i]] = i;
sort(v.begin(), v.end(), compare);

for(auto x : v)
cout<<x<<" ";

return 0;
}

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

Python Solutions. Two ways to solve it-
1.

``````string = 'ABDEKCL'
print(''.join(string))``````

output- ABCDEKL

2.

``````a = 'ABDEKCL'
arr = []
for i in a:
arr.append(ord(i))

arr.sort()
st = ''
for i in arr:
st += chr(i)

print(st)``````

output- ABCDEKL

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.

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.