Microsoft Interview Question for Software Developers


Country: Israel
Interview Type: Phone Interview




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

Initiate random number with value 0 to n. get a number from this function and then swap this number with last number of array. then call the random fucntion with 0 to n-1... and swap the number with n-1 index and repeat the process.

- sandeepmnit35 July 10, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

you can use an array to shuffle songs.With the help of a pseudorandomgenerator,we generate random numbers from 1 to 100 whatever number comes up play that song and then continue the loop with 2 to n then 3 to n and so on whatever number comes up just swap it with the first number.

- Shivangi July 17, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String[] songs = {"Muse - Dead Inside","Scorpions - Send Me An Angel",
            "RHCP - Californication","Scorpions - Wind of Change","Muse - Psycho",
            "Metallica - Fade to Black","Apple - Binary Symphony"};
            ArrayList <String> array = new ArrayList<>();
        System.out.println("UNSORTED LIST");
                for(int i=0;i<=100;i++) {
                    int randnum = (int) Math.floor(Math.random() * songs.length);
                    for (int i1=0; i1<=array.size(); i1++){
                        if (!array.contains(songs[randnum])){
                            System.out.println(songs[randnum]);
                            array.add(songs[randnum]);
                        }
                    }
                }
                Set<String> seted = new TreeSet<>(array);
        Object[] objects = ((TreeSet<String>) seted).headSet(String.valueOf(((TreeSet<String>) seted).isEmpty())).toArray();
        System.out.println();
        System.out.println("SORTED LIST(ALPHABETICALLY)");
                for (int i = 0; i<objects.length; i++) {
                    System.out.println(objects[i]);
                }

- xidonett August 07, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what

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

var songs [
       {
         id: 1, 
         song: "doom dom"
       }, 
       {
         id: 100, 
         song: "all other songs in between"
       }
    ]

    let playedSongs = [];


    function findNextSong() {
      let nextSongId = songs.length * Math.random();

      if(playedSongs.includes(nextSongId)){
        findNextSong()
      }

      playedSongs.push(nextSongId);
      return nextSongId;

    }

    shuffle() {
      const nextSongId = findNextSong();

      return playSong(nextSongId);
    }

    playSong(songId) {
      // write play song algorithm here
    }

- Suman Kharel November 27, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

var songs =  [
       {
         id: 1, 
         song: "doom dom"
       }, 
       {
         id: 100, 
         song: "all other songs in between"
       }
    ]

    let playedSongs = [];


    function findNextSong() {
      let nextSongId = songs.length * Math.random();

      if(playedSongs.includes(nextSongId)){
        findNextSong()
      }

      playedSongs.push(nextSongId);
      return nextSongId;

    }

   function shuffle() {
      const nextSongId = findNextSong();

      return playSong(nextSongId);
    }

    function playSong(songId) {
      // write play song algorithm here

}

- Suman Kharel November 27, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

var songs = [
{
id: 1,
song: "doom dom"
},
{
id: 100,
song: "all other songs in between"
}
]

let playedSongs = [];


function findNextSong() {
let nextSongId = songs.length * Math.random();

if(playedSongs.includes(nextSongId)){
findNextSong()
}

playedSongs.push(nextSongId);
return nextSongId;

}

function shuffle() {
const nextSongId = findNextSong();

return playSong(nextSongId);
}

function playSong(songId) {
// write play song algorithm here
}

- Anonymous November 27, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

I took 10 songs, you can take 100 :)
Python

playlist = set(['song1', 'song2', 'song3', 'song4', 'song5', 'song6', 'song7','s8','s9','s10'])
for n in range(len(playlist)):
    print('Now playing...' + playlist.pop())
print('Playlist finish, if you want, i can solve this using OOP design')

- manmaybarot July 19, 2018 | 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