MagicBricks
P-Mech Consultant Interview Questions and Answers
Q1. Sort 0 1 2 Problem Statement
Given an integer array arr
of size 'N' containing only 0s, 1s, and 2s, write an algorithm to sort the array.
Input:
The first line contains an integer 'T' representing the number of...read more
Sort an integer array containing only 0s, 1s, and 2s in linear time complexity.
Use three pointers to keep track of the positions of 0s, 1s, and 2s in the array.
Iterate through the array and swap elements based on the values encountered.
Achieve sorting in a single scan over the array without using any extra space.
Q2. Cycle Detection in a Singly Linked List
Determine if a given singly linked list of integers forms a cycle or not.
A cycle in a linked list occurs when a node's next
points back to a previous node in the list. T...read more
Detect if a singly linked list forms a cycle by checking if a node's next points back to a previous node.
Traverse the linked list using two pointers, one moving one step at a time and the other moving two steps at a time.
If the two pointers meet at any point, there is a cycle in the linked list.
If one of the pointers reaches the end of the list (null), there is no cycle.
Q3. N Queens Problem
Given an integer N
, find all possible placements of N
queens on an N x N
chessboard such that no two queens threaten each other.
Explanation:
A queen can attack another queen if they are in the...read more
The N Queens Problem involves finding all possible placements of N queens on an N x N chessboard where no two queens threaten each other.
Use backtracking algorithm to explore all possible configurations.
Keep track of rows, columns, and diagonals to ensure queens do not attack each other.
Generate and print valid configurations where queens are placed safely.
Consider constraints and time limit for efficient solution.
Example: For N=4, valid configurations are: 0010100000101000 a...read more
Q4. Balanced Parentheses Combinations
Given an integer N
representing the number of pairs of parentheses, find all the possible combinations of balanced parentheses using the given number of pairs.
Explanation:
Con...read more
Generate all possible combinations of balanced parentheses for a given number of pairs.
Use recursion to generate all possible combinations of balanced parentheses.
Keep track of the number of open and close parentheses used in each combination.
Return the valid combinations as an array of strings.
Q5. Ninja and Substrings Problem Statement
Ninja has to determine all the distinct substrings of size two that can be formed from a given string 'STR' comprising only lowercase alphabetic characters. These substrin...read more
Find all unique contiguous substrings of size two from a given string.
Iterate through the string and extract substrings of size two
Use a set to store unique substrings
Return the set as an array of strings
Q6. Launch modes on android
Launch modes on Android determine how a new instance of an activity is associated with the current task.
Standard: Creates a new instance of the activity in the task's stack
SingleTop: If an instance of the activity already exists at the top of the stack, it will not be recreated
SingleTask: Activity is always at the root of the task and no other activities can be on top of it
SingleInstance: Similar to SingleTask, but the activity is launched in a new task
Interview Process at P-Mech Consultant
Top Software Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month