Check If a Binary Tree Is an Even-Odd Tree

Divya Sahni
Updated on 25-Oct-2023 13:01:21

256 Views

Even-Odd Tree − A binary tree is called an even-odd tree if all the nodes at the even level (taking root node at level 0) have even values and all the nodes at the odd level have odd values. Problem Statement Given a binary tree. The task is to check if the binary tree is an even-odd tree or not. Sample Example 1 Input 6 / \ 3 7 / \ ... Read More

Check Binary Tree Node Values in Increasing and Decreasing Order

Divya Sahni
Updated on 25-Oct-2023 12:51:49

112 Views

Level of a Binary Tree − In a binary tree, the level of the node refers to its distance from the root node. The root node is considered at level 0, its immediate children are at level 1, their children at level 2 and so on. Levels of a binary tree are explained in the following example, A

Array Obtained by Repeatedly Reversing After Every Insertion

Divya Sahni
Updated on 25-Oct-2023 12:50:05

136 Views

Array insertion and reversal are one of the most common array manipulation techniques. Array manipulation aims to modify an array's contents to get a desired outcome. Problem Statement Given an input array A[]. The task is to insert the elements of the given array into an existing array where a reversal of the output array follows each insertion. Sample Example 1 − Input: A[] = {1, 2, 3, 4, 5} Output: R[] = {5, 3, 1, 2, 4} Explanation Initially, the output array R[] is empty. Insertion of 1 : R[] = {1} Insertion of 2 : ... Read More

Print Frequency of Adjacent Repeating Characters in a String

Vanshika Sood
Updated on 25-Oct-2023 12:05:37

264 Views

A string is a data structure consisting of a sequence of characters. The end of the string is marked by a special character, called a null character, which is usually represented by the ASCII code 0. Problem Statement Given a string s of a certain length, the task at hand is to print adjacent repeating characters along with the frequency of their repetition. For Example Input: s = “committee” Output: [[m, 2], [t, 2], [e, 2]] Explanation The character m occurs consecutively twice. Similarly the character t and e also occur twice consecutively. Therefore we return the vector ... Read More

Minimize Removals to Remove Another String as a Subsequence

Vanshika Sood
Updated on 25-Oct-2023 12:01:38

302 Views

A subsequence refers to a sequence that can be obtained from another sequence by removing zero or more elements, without altering the order of the remaining elements. In simpler terms, a subsequence is derived by selecting elements from the original sequence, while preserving their relative order. For example, consider the sequence [1, 2, 3, 4]. Some possible subsequences of this sequence are: [1, 2], [1, 3, 4], [2, 4], [1, 2, 3, 4], [3], and [4]. Problem Statement The objective is to determine the minimum number of character removals from string s1 in order to eliminate any occurrence of ... Read More

Check If Given String Is Prefix Subarray of the Given Array

Vanshika Sood
Updated on 25-Oct-2023 11:59:25

268 Views

A subarray of an array is a contiguous part of the array in which we take a group of consecutive elements while also maintaining the relative ordering of elements as present in the original array. Example − Some valid subarrays are − etc. A prefix subarray is a special type of subarray that begins with the first element of the array and ends at some ith index where 0

Check If Every Row in Matrix Contains All Integers from 1 to N

Vanshika Sood
Updated on 25-Oct-2023 11:52:35

251 Views

A matrix is a two-dimensional data structure made up of rows and columns set out like a grid of squares. Grids, multidimensional arrays, and tabular data are frequently represented using it. Problem Statement We are given a matrix of dimensions and the task is to check whether each row of the matrix consists of every number from 1 to n. The order of the numbers in the row do not matter. Return true if this statement holds true else return false. For Example Input: mtx = [[1, 2, 3], [3, 2, 1], [2, 1, 3]] Output: True ... Read More

Minimize Replacement of Characters to Nearest Alphabet for Palindrome

Siva Sai
Updated on 23-Oct-2023 16:15:35

495 Views

In this article, we will discuss a fascinating algorithmic problem: "Minimize replacement of characters to its nearest alphabet to make a string palindromic." This problem is intriguing because it involves string manipulation, palindrome checking, and the concept of ASCII values for characters. Let's dive into the problem. Problem Statement Given a string of characters, the task is to transform it into a palindrome with the minimum number of replacements. These replacements are made by changing a character to its nearest alphabet. Understanding the Problem A palindrome is a word, phrase, number, or other sequences of characters that reads the same ... Read More

Minimize Removal of Non-Equal Adjacent Characters to Make String Empty

Siva Sai
Updated on 23-Oct-2023 16:12:18

966 Views

In this article, we'll be diving into a fascinating string manipulation problem. The problem statement is "Minimize removal of non-equal adjacent characters required to make a given string empty". This problem is a fantastic way to enhance your understanding of strings, character removal, and algorithmic thinking. Problem Statement Given a string, the task is to minimize the number of removal operations of non-equal adjacent characters required to make the given string empty. In one operation, you can remove any two adjacent characters that are not equal. Solution Approach The approach to solve this problem is using a stack data structure. ... Read More

Minimize Operations to Make String Palindrome by Incrementing Prefix by 1

Shubham Vora
Updated on 23-Oct-2023 16:10:04

239 Views

In this problem, we will count the number of operations required by increasing the prefix characters of the given string. We will use character difference to count the minimum number of operations required to make string palindromic. Problem Statement We have given a string nums containing the numeric digits. We need to count a minimum number of operations required to convert a string into the palindrome. In one operation, we can select any prefix of the string and increment all prefix characters by 1. Sample Example Input nums = "22434" Output 2 Explanation ... Read More

Advertisements