Add office photos
PubMatic logo
Premium Employer

PubMatic

Verified
3.9
based on 118 Reviews
Video summary
Filter interviews by
SDE-2
Clear (1)

PubMatic SDE-2 Interview Questions and Answers

Updated 5 Feb 2024

Q1. Binary Tree Zigzag Traversal Problem Statement

Given a Binary Tree comprised of 'N' nodes with integer values, your task is to print the zigzag traversal of the tree.

Note:

The zigzag pattern implies that the f...read more

Ans.

Implement a function to print the zigzag traversal of a Binary Tree.

  • Traverse the Binary Tree level by level, alternating the direction of traversal for each level.

  • Use a queue to keep track of nodes at each level and a flag to switch the direction of traversal.

  • Print the values of nodes in the zigzag order as described in the problem statement.

Add your answer
right arrow

Q2. Time to Burn Tree Problem

You are given a binary tree consisting of 'N' unique nodes and a start node where the burning will commence. The task is to calculate the time in minutes required to completely burn th...read more

Ans.

Calculate the time in minutes required to completely burn a binary tree starting from a given node.

  • Start burning from the given node and spread fire to adjacent nodes each minute

  • Track the time taken for each node to burn completely

  • Return the maximum time taken to burn the entire tree

Add your answer
right arrow

Q3. Trailing Zeros in Factorial Problem

Find the number of trailing zeroes in the factorial of a given number N.

Input:

The first line contains an integer T representing the number of test cases.
Each of the followi...read more
Ans.

Count the number of trailing zeros in the factorial of a given number.

  • Count the number of factors of 5 in the factorial of the given number N.

  • Divide N by 5, then by 25, then by 125, and so on, and sum up the quotients to get the total number of trailing zeros.

  • Example: For N=10, 10/5=2, so there are 2 factors of 5 in 10!, hence 2 trailing zeros.

Add your answer
right arrow

Q4. Loot Houses Problem Statement

A thief is planning to steal from several houses along a street. Each house has a certain amount of money stashed. However, the thief cannot loot two adjacent houses. Determine the...read more

Ans.

Determine the maximum amount of money a thief can steal from houses without looting two consecutive houses.

  • Use dynamic programming to keep track of the maximum money that can be stolen up to each house.

  • At each house, the thief can either choose to steal from the current house or skip it and steal from the previous house.

  • The maximum amount of money that can be stolen without looting two consecutive houses is the maximum of the two options.

Add your answer
right arrow
Discover PubMatic interview dos and don'ts from real experiences

Q5. Convert Binary Tree to Mirror Tree

Convert a given binary tree into its mirror tree, where the left and right children of all non-leaf nodes are interchanged.

Input:

An integer ‘T’ denoting the number of test c...read more
Ans.

Convert a binary tree into its mirror tree by interchanging left and right children of non-leaf nodes.

  • Traverse the tree in a recursive manner and swap the left and right children of each node.

  • Use a temporary variable to swap the children of each node.

  • Ensure to modify the tree in place without creating a new tree.

  • Example: For the input tree 1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1, the mirror tree will have inorder traversal as 7 4 2 1 6 3 5.

Add your answer
right arrow

Q6. Topological Sort Problem Statement

Given a Directed Acyclic Graph (DAG) consisting of V vertices and E edges, your task is to find any topological sorting of this DAG. You need to return an array of size V repr...read more

Ans.

Implement a function to find any topological sorting of a Directed Acyclic Graph (DAG).

  • Use Depth First Search (DFS) to find the topological ordering of the vertices.

  • Start by visiting a vertex and recursively visit its adjacent vertices before adding it to the result array.

  • Maintain a visited array to keep track of visited vertices and avoid cycles.

  • Once all vertices are visited, reverse the result array to get the topological sort.

  • Example: For a DAG with edges 0->1, 0->3, 1->2,...read more

Add your answer
right arrow
Contribute & help others!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
interview tips and stories logo
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top SDE-2 Interview Questions from Similar Companies

Amazon Logo
4.1
 • 39 Interview Questions
Walmart Logo
3.7
 • 19 Interview Questions
Microsoft Corporation Logo
4.0
 • 16 Interview Questions
PayPal Logo
3.9
 • 14 Interview Questions
View all
Recently Viewed
INTERVIEWS
Pioneer e Solutions
No Interviews
INTERVIEWS
Intellias
No Interviews
REVIEWS
Merkle Sokrati
No Reviews
REVIEWS
MAHLE ANAND Filter Systems
No Reviews
SALARIES
MAHLE ANAND Filter Systems
LIST OF COMPANIES
Infosys Public Services
Overview
REVIEWS
Infosys Public Services
No Reviews
INTERVIEWS
Intellias
No Interviews
SALARIES
Infosys Public Services
SALARIES
MAHLE ANAND Filter Systems
Share an Interview
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
75 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter