Microsoft Interview Question for Software Developers


Team: Cloud + Enterprise
Country: United States
Interview Type: Written Test




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

public static void MigrateMovies(IDataReader  dataReader,
							MovieInformationDataBase db){
	if(dataReader == null || db == null) throw new ArgumentNullException("...");
	int movieOrdinal = dataReader.GetOrdinal("MovieName");
	int contributorTypeOrdinal = dataReader.GetOrdinal("ContributorType");
	int contributorNameOrdinal = dataReader.GetOrdinal("ContributorName");
	string currentMovie = null;
	MovieInformation movInfo;
	while(dataReader.Read()){
		string movieName = dataReader.GetString(movieOrdinal);
		string contributorType = dataReader.GetString(contributorTypeOrdinal);
		string contributorName = dataReader.GetString(contributorNameOrdinal);
		if(string.IsNullOrEmpty(movieName) || string.IsNullOrEmpty(contributorType)
			|| string.IsNullOrEmpty(contributorName) )
			continue;
		if(!movieName.
			Equals(currentMovie,StringComparison.CultureInvariantIgnoreCase))
		{
			if(movInfo!=null){
				db.SaveMovieInformation(movInfo);
			}
			currentMovie = movieName;
			movInfo = new MovieInformation{Name = movieName, Actors = new List<string>()};
		}
		
		if(contributorType.Equals("Director",StringComparison.IgnoreCase)){
			//Assuming the database has only one director per movie
			movInfo.Director = contributorName;
		}
		if(contributorType.Equals("Actor",StringComparison.IgnoreCase)){
			movInfo.Actors.Add(contributorName):
		}
			
	}

- Anonymous March 21, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void TransferMoveInformation(IDataReader movieDataReader, MovieInformationDataBaseAccess movieInformationDataBaseAccess)
{
    int movieNameOrdinal = movieDataReader.GetOrdinal("MovieName");
    int contributorTypeOrdinal = movieDataReader.GetOrdinal("ContributorType");
    int contributorNameOrdinal = movieDataReader.GetOrdinal("ContributorName");
    string previousMovieName = string.Empty;
    MovieInformation newMovieInformation = null;
    while(movieDataReader.Read())
    {
        string nextMovieName = movieDataReader.GetString(movieNameOrdinal);
        if(!nextMovieName.Equals(previousMovieName, StringComparison.CultureInvariantIgnoreCase))
        {
            if(newMovieInformation != null)
            {
                // check if all the objects are filled, if not we can log it to or not insert it, this action should be taken by the business
                movieInformationDataBaseAccess.SaveMovieInformation(newMovieInformation)
            }
            newMovieInformation = new MovieInformation();
            newMovieInformation.Name = nextMovieName;
            previousMovieName = nextMovieName;
        }
        string nextContributorType = movieDataReader.GetString(contributorTypeOrdinal);
        string nextContributorName = movieDataReader.GetString(contributorNameOrdinal);
        if(nextContributorType.Euqals("Director", StringComparison.CultureInvariantIgnoreCase))
        {
            if(string.IsEmptyOrNull(newMovieInformation.Director))
            {
                newMovieInformation.Director = nextContributorName;
            }
            else if(!newMovieInformation.Director.Equals(nextContributorName, StringComparison.CultureInvariantIgnoreCase))
            {
                // this is also an error situation, one should either log them or let business take the action on these
            }
        }
        else if(nextContributorType.Euqals("Actor", StringComparison.CultureInvariantIgnoreCase)
        {
            if(newMovieInformation.Actors == null)
            {
                newMovieInformation.Actors = new List<string>(){nextContributorName};
            }
            else
            {
                bool isNotAlreadyPresent = true;
                foreach(string actor in newMovieInformation.Actors)
                {
                    if(actor.Equals(nextContributorName, StringComparison.CultureInvariantIgnoreCase))
                    {
                        isAlreadyPresent = false;
                    }
                }
                if(isAlreadyPresent)
                {
                    newMovieInformation.Actors.Add(nextContributorName);
                }
            }
        }
        else
        {
            // we can log this as well to tell that we have some extra information which we are losing or we are having some corrupted data, we can even do some string partial match to decide if it is close to director or actor and take actions based upon that
        }
    }
}

- sonesh June 29, 2015 | 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