GOOGLE L3 ONSITE R1

google logo
google
SDE I
April 28, 20252 reads

Summary

I participated in an onsite interview for Google L3 where I was presented with two data structure and algorithm problems. I successfully solved a problem involving merging changelog files with version conflict resolution and a follow-up problem to parse changelog file content into a structured format.

Full Experience

You are two files of Changelogs with version and it's messages. You have to merge both of the files into the one. All the version values inside the changelog files are sorted in descending order.

If there is a conflict of any version between two files, merge them up and the message ordering should be consistent in accordance with ChangeLog from first files to be taken first then from the second file.

Print the changes after merging the changes.

Example : ChangeLog File1:

24.0.1

Added Export functionality Fixed the template issue.

23.0.2

Added Foreign key to template table.

ChangeLog File2:

24.0.2

Created index on template.

23.0.2

Resolved merge conflicts.

Output: 24.0.2

Created index on template.

24.0.1

Added Export functionality Fixed the template issue.

23.0.2

Added Foreign key to template table. Resolved merge conflicts.

My Approach : As initially, I was a function signature of mergeChangeLogFiles(List file1, List file2) where Pair denotes : class Pair { String versionNumber; List messages; }

So, I used a normal merge approach using two individual pointers for these two list and verified whosoever was greater with version number, gets printed first. But incase of conflict, it gets prioritized by file1 messages then by file2 for that particular version number and both indexes are incremented further.

For non-printed versions, got that covered up as well by printing them individually.

Interviewer was fine with my approach.

Follow Up : Now, I had to write a helper function to extract the text from the changeLog files in the List format.

List helper(String changeLogFile);

My Approach : Gave the approach to split the string by line break('\n') and parse each version number first, then from current index move two indices ahead so to avoid '------' string. Added the messages into the pair until a new line break occured and added it to the result. Interviewer seemed satisfied with my approach and I was able to both them.

Interview Questions (2)

Q1
Merge Changelog Files
Data Structures & Algorithms

You are two files of Changelogs with version and it's messages. You have to merge both of the files into the one. All the version values inside the changelog files are sorted in descending order.

If there is a conflict of any version between two files, merge them up and the message ordering should be consistent in accordance with ChangeLog from first files to be taken first then from the second file.

Print the changes after merging the changes.

Example : ChangeLog File1:

24.0.1

Added Export functionality Fixed the template issue.

23.0.2

Added Foreign key to template table.

ChangeLog File2:

24.0.2

Created index on template.

23.0.2

Resolved merge conflicts.

Output: 24.0.2

Created index on template.

24.0.1

Added Export functionality Fixed the template issue.

23.0.2

Added Foreign key to template table. Resolved merge conflicts.

Q2
Parse Changelog File to List<Pair>
Data Structures & Algorithms

I had to write a helper function to extract the text from the changeLog files in the List format.

List helper(String changeLogFile);

Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!