VMWare Inc Interview Question


Country: United States
Interview Type: Phone Interview




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

list.sort(Comparator.naturalOrder())

- tyler_ua July 11, 2018 | Flag Reply
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;
                }
            }
        }

- Madhusudhan July 11, 2018 | Flag Reply
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;
}
}
}

- Madhusudhan July 11, 2018 | Flag Reply
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)

- PrabhakarShah July 11, 2018 | Flag Reply
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.

- Anonymous July 15, 2018 | Flag Reply
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.

- sarunreddy82 July 15, 2018 | Flag Reply
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]);
}

}

}

- Anonymous July 18, 2018 | Flag Reply
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 ) );
    }
}

- cvishwakarma July 18, 2018 | Flag Reply
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

- undefined July 25, 2018 | Flag Reply
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;
}

- swapnilkant11 May 29, 2019 | Flag Reply
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

- Shivam Bhirud May 17, 2021 | 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