Home
Jobs
Interview Questions for Krishna Computer Sales Service

1. All Root to Leaf Paths in Binary Tree You have a binary tree containing 'N' nodes labeled from 1 to 'N'. Your objective is to enumerate every path from the root to each leaf. A leaf is defined as a node with no child nodes. Example: Input Given a binary tree: Output All the root to leaf paths are:1 2 41 2 51 3 Input: The first line of the input contains a single integer 'T', representing the number of test cases.The first line of each test case holds an integer 'N', denoting the number of nodes in the tree.The second line of each test case contains the node values of the tree in level order format ('-1' represents a NULL node). Output: For each test case, output all paths from root to leaf. Example: Consider the binary tree: The input for the depicted tree:12 34 -1 5 6-1 7 -1 -1 -1 -1-1 -1 Explanation Level 1:The root node of the tree is 1Level 2:Left child of 1 = 2Right child of 1 = 3Level 3:Left child of 2 = 4Right child of 2 = null (-1)Left child of 3 = 5Right child of 3 = 6Level 4:Left child of 4 = null (-1)Right child of 4 = 7Left child of 5 = null (-1)Right child of 5 = null (-1)Left child of 6 = null (-1)Right child of 6 = null (-1)Level 5:Left child of 7 = null (-1)Right child of 7 = null (-1) Constraints: 1 <= T <= 102 1 <= N <= 3 * 103 Note: You do not need to print anything. Implement the given function to solve the problem.

2. Count Diagonal Paths You are given a binary tree. Your task is to return the count of the diagonal paths to the leaf of the given binary tree such that all the values of the nodes on the diagonal are equal. Input: The first line of input contains an integer ‘T’ denoting the number of test cases.The following ‘T’ lines represent the ‘T’ test cases.Each test case line contains the elements of the tree in level order form, separated by a single space. Use -1 to denote a missing child. Output: For each test case, return the count of the diagonal paths to the leaf of the given binary tree such that all the values of the nodes on the diagonal are equal. Example: Input: 5 6 5 -1 6 -1 5 -1Output: 2Explanation: Diagonal 6 – 6 and 5 – 5 contains equal values. Therefore, the required output is 2. Constraints: 1 <= T <= 100 1 <= N <= 3000 1 <= data <= 10^9 Note: The sequence in the input for the tree nodes is given in a single line with values separated by a single space, where -1 denotes a null node.For example, for the tree: 1 / \ 4 2 / \ \ 8 5 3 / \ / 9 7 6The input will be: 1 4 2 8 5 -1 3 -1 -1 9 7 6 -1 -1 -1 -1 -1 -1

3. Longest Increasing Subsequence Problem Statement Given an array of integers with 'N' elements, determine the length of the longest subsequence where each element is greater than the previous element. This subsequence must be in strictly increasing order. Example: Input: N = 4array = [1, 2, 3, 4] Output: 4 Explanation: The longest strictly increasing subsequence is the array itself, [1, 2, 3, 4], which has a length of 4. Constraints: 1 <= N <= 10^5 -10^5 <= element <= 10^5 Time Limit: 1 second Note: You do not need to print anything; it has already been taken care of. Just implement the given functions.

4. Count Subsequences Problem Statement Given an integer array ARR of size N, your task is to find the total number of subsequences in which all elements are equal. Explanation: A subsequence of an array is derived by removing some of the elements of the array without changing the order of the remaining elements. Input: The first line contains an integer 'T' denoting the number of test cases. Each test case is as follows: The first line contains an integer 'N' denoting the size of the array. The second line contains 'N' space-separated integers representing the elements of the array. Output: For each test case, output the total number of subsequences where all elements are the same. Each test case's result should be printed on a new line. Example: Input: 2 3 1 1 2 4 3 3 3 3 Output: 3 14 Constraints: 1 ≤ T ≤ 100 1 ≤ N ≤ 105 0 ≤ ARR[i] ≤ 109 Time Limit: 1 second Note: The result must be calculated modulo 109 + 7. Implement the function; you don't need to print anything.

cta

Start Your Job Search Today

Browse through a variety of job opportunities tailored to your skills and preferences. Filter by location, experience, salary, and more to find your perfect fit.

Job Application AI Bot

Job Application AI Bot

Apply to 20+ Portals in one click

Download Now

Download the Mobile App

Instantly access job listings, apply easily, and track applications.

Job Titles Overview