Found 34494 Articles for Programming

Print all Exponential Levels of a Binary Tree

Shubham Vora
Updated on 25-Aug-2023 16:01:21

94 Views

In this problem, we will print all exponential levels of the binary tree. We will use the level order traversal to traverse through each level of the binary tree. After that, we will find minimum P and q values using the first element of the level. In the next step, we can check whether other level values are exponential. Problem Statement We have given a binary tree. We need to print values of all exponential levels of the binary tree. It is given if the values of each node of the level of the binary tree are equal ... Read More

How to check for spaces in Python string?

Pranavnath
Updated on 25-Aug-2023 16:10:23

4K+ Views

In the current 21st century, handling data is the most challenging task for organizations with a high volume of data and with the development of data science and machine learning it has become easier to access. The spaces are also known as the whitespaces in between the characters of strings. The space has no data or it is simply empty and it creates a problem for programmers while coding. So, in order to check for spaces in the string involves many methods and some are explained here. Strings are composed of characters and Python Language comes under the OOPS concept ... Read More

Minimum difference between maximum and minimum value of Array with given Operations

Shubham Vora
Updated on 25-Aug-2023 16:00:17

142 Views

In this problem, we will find the minimum difference between minimum and maximum array elements after multiplying or dividing any array elements with K. The simple approach to solving the problem is dividing each element of the array with K if divisible, multiplying each element with K, and tracking the array's minimum and maximum elements. Problem Statement We have given array nums[] containing the integer values and positive integer K. We can multiply any number of the nums[] array with K or divide it by K if it is divisible. The given task is to find the minimum difference between ... Read More

Python – Alternate front – rear sum

Pranavnath
Updated on 25-Aug-2023 16:08:10

78 Views

One of the most important data types is List in the Python language. Various inbuilt methods to be available in python to manipulate the list items like append(), insert(), extend() and so on. Multiple approaches help in finding the alternate front-rear sum of an array. The array is given with n elements and the process involved are first element is added to the last element of the array, second element of an array is added to the second last element value and it continues until all the elements are added together. For example, let’s take the array, [40, 50, ... Read More

Minimum circular rotations to obtain a given numeric string by avoiding a set of given strings

Shubham Vora
Updated on 25-Aug-2023 15:59:09

67 Views

In this problem, we will find the number of rotations required to achieve the target string from the string containing N 0s. Also, we will skip the strings given in the array while making rotations. We can use the BFS algorithm to find the minimum rotations required to get the target string. Problem Statement We have given a target string containing the N numeric characters. Also, we have given the strs[] array containing the M strings of size N containing the numeric characters. We need to initially achieve the target string from a string containing N 0's by performing the ... Read More

Implementing Water Supply Problem using Breadth First Search

Shubham Vora
Updated on 25-Aug-2023 15:57:37

68 Views

In this problem, we will find the maximum number of cities to which we can supply water. We can consider this problem as a graph traversing the blocked node. So, we can use the breadth-first search algorithm to find the maximum number of connected cities. Problem Statement We have given the total N cities. Also, we have given an edge between two cities; all cities are connected with any other single or multiple cities. We need to set up the water supply connection in each city. We have also given the blocked[] array containing the 0 and 1 values. ... Read More

Find integral points with minimum distance from given set of integers using BFS

Shubham Vora
Updated on 25-Aug-2023 15:56:00

43 Views

In this problem, we will find the K points which are nearest to any of the given points from the points given in the array. To find the points which are nearest to the given points, we can take the nums[p] + 1 or nums[p] -1 for each element of the array if it is not present in the array. If we require more points, we can take the nums[p] + 2 or nums[p] – 2 points, and so on. Problem Statement We have given a nums[] array containing the N positive and negative integers. Each point of ... Read More

Clockwise Triangular traversal of a Binary Tree

Shubham Vora
Updated on 25-Aug-2023 15:54:54

118 Views

In this problem, we will create a complete binary tree and traverse it in a circular clockwise direction. For the clockwise traversal, we can think of traversing the boundaries of the tree. For example, we can traverse the outer boundary of the tree first. After that, we can remove visited nodes and traverse the inner boundary of the tree. In this way, we need to make min(height/2, width/2) traversal of the given binary tree. Problem Statement We have given a complete binary tree containing N nodes and need to traverse it in a clockwise direction. Sample Examples Input n ... Read More

Check if the Left View of the given tree is sorted or not

Shubham Vora
Updated on 25-Aug-2023 15:53:45

68 Views

In this problem, we will check whether the left view of the binary tree is sorted. The left view of the binary tree means nodes we can see when we look at the binary tree from the left side. In simple terms, we can see only the first node of each level. So, we need to extract the value of the first node and check whether they are sorted to get the output. Problem Statement We have given a binary tree. We need to print whether the binary tree's left view is sorted. If it is sorted, print 'Yes'. ... Read More

Check if cells numbered 1 to K in a grid can be connected after removal of atmost one blocked cell

Shubham Vora
Updated on 25-Aug-2023 15:52:11

39 Views

In this problem, we will check whether we can connect all K cells by unblocking any single cell. To solve the problem, we will assume all connected K as a single Island. If any single blocked cell can connect all Island of the matrix, it is only possible to connect all K cells of the matrix. So, If the matrix contains more than 4 Island, it is not possible to connect all cells. Problem Statement We have given a mat[] matrix of size n*m. We have also given a positive integer, K. The matrix contains 0 and -1 in ... Read More

Advertisements