### Similar Reads

Program to find Length of Bridge using Speed and Length of Train Given the Length and Speed of the train and the time takes by the train to passes the bridge or tunnel, the task is to find the length of the bridge.Examples: Input : length of train = 120 meters, Speed = 30 m/sec, time = 18 sec Output : length of bridge = 420 meters.Input : length of train = 130 meters, Speed = 25 m/sec, time = 21 sec Output : len 4 min read Minimum length of Run Length Encoding possible by removing at most K characters from a given string Given a string S of length N, consisting of lowercase English alphabets only, the task is to find the minimum possible length of run-length-encoding that can be generated by removing at most K characters from the string S. Examples: Input: S = "abbbcdcdd", N = 9, K = 2 Output: 5 Explanation: One possible way is to delete both occurrences of 'c' fro 10 min read C++ Program for Queries to find maximum sum contiguous subarrays of given length in a rotating array Given an array arr[] of N integers and Q queries of the form {X, Y} of the following two types: If X = 1, rotate the given array to the left by Y positions.If X = 2, print the maximum sum subarray of length Y in the current state of the array. Examples: Input: N = 5, arr[] = {1, 2, 3, 4, 5}, Q = 2, Query[][] = {{1, 2}, {2, 3}}Output:Query 1: 3 4 5 5 min read How to Find the Length of a Substring in a char Array? In C++, a substring is a string inside another string that is the contiguous part of the string. In this article, we will learn how to find the length of a substring in a char array in C++. Example Input: str[] = "Hello, World!";substr= "World";Output: Length of substring World is: 5Finding Length of Substring Within Char Array in C++To find the le 2 min read 5 Different Methods to Find Length of a String in C++ The string is a sequence of characters or an array of characters. The declaration and definition of the string using an array of chars are similar to the declaration and definition of an array of any other data type. Examples: Input: "Geeksforgeeks" Output: 13 Input: "Geeksforgeeks \0 345" Output: 14Important PointsThe constructor of the String cla 4 min read Find longest length number in a string Given a string of digits and characters. Write a program to find the number with the maximum number of digits in a string. Note: The number may not be the greatest number in the string. For example, if the string is "a123bc321" then the answer can be 123 or 321 as the problem is to find the number with the longest length and not the largest value.E 6 min read Find words which are greater than given length k using stringstream Given a string containing space-separated words and a number K. The task is to find and print all those words whose length is greater than K using stringstream in C++. A general solution to solve this problem using loops is discussed in the previous article. In this article, a solution using stringstream in C++ will be discussed. Examples: Input : 4 min read Find length of Diagonal of Hexagon Given a regular hexagon of side length a, the task is to find the length of it's diagonal.Examples: Input : a = 4 Output : 8 Input : a = 7 Output : 14 From the diagram, it is clear that the triangle ABC is an equilateral triangle, so AB = AC = BC = a.also it is obvious, diagonal = 2*AC or 2*BC So the length of diagonal of the hexagon = 2*aBelow is 3 min read Find the number of binary strings of length N with at least 3 consecutive 1s Given an integer N. The task is to find the number of all possible distinct binary strings of length N which have at least 3 consecutive 1s.Examples: Input: N = 3 Output: 1 The only string of length 3 possible is "111".Input: N = 4 Output: 3 The 3 strings are "1110", "0111" and "1111". Naive approach: Consider all possible strings.Below is the impl 9 min read Find two equal subsequences of maximum length with at least one different index Given a string str, the task is to find the maximum length K such that there exist two sub-sequences A and B each of length K such that A = B and number of common indices between A and B is at most K - 1.Examples: Input: str = "geeksforgeeks" Output: 12 The two subsequences are str[0...1] + str[3...12] = "geksforgeeks" and str[0] + str[2...12] = "g 6 min read Find length of loop in a Linked List using Map Write a program that checks whether a given Linked List contains a loop and if a loop is present then returns the count of nodes in the loop. For example, a loop is present in the below-linked list and the length of the loop is 4. If the loop is not present, then the function should return 0. Approach: In this post, we will use the concept of Map t 7 min read C++ Program To Find Length Of The Longest Substring Without Repeating Characters Given a string str, find the length of the longest substring without repeating characters. For “ABDEFGABEF”, the longest substring are “BDEFGA” and "DEFGAB", with length 6.For “BBBB” the longest substring is “B”, with length 1.For "GEEKSFORGEEKS", there are two longest substrings shown in the below diagrams, with length 7 The desired time complexit 6 min read Length of longest subarray for each index in Array where element at that index is largest Given an array arr[] of size N, the task is to calculate, for i(0<=i<N), the maximum length of a subarray containing arr[i], where arr[i] is the maximum element. Example: Input : arr[ ] = {62, 97, 49, 59, 54, 92, 21}, N=7Output: 1 7 1 3 1 5 1Explanation: The maximum length of subarray in which 1st index element is maximum is 1, the subarray c 15 min read Maximum length sub-array which satisfies the given conditions Given an array arr[] of N integers, the task is to find the maximum length of any sub-array of arr[] which satisfies one of the given conditions: The subarray is strictly increasing.The subarray is strictly decreasing.The subarray is first strictly increasing then strictly decreasing. Examples: Input: arr[] = {1, 2, 2, 1, 3} Output: 2 {1, 2}, {2, 1 9 min read Minimize length of an array consisting of difference between all possible pairs Given an array arr[] of size N, the task is to find the minimum count of elements required to be inserted into the array such that the absolute difference of all possible pairs exists in the array. Examples: Input: arr[] = { 3, 5 } Output: 3 Explanation: Inserting 2 into the array modifies arr[] to { 2, 3, 5 } Inserting 1 into the array modifies ar 8 min read Minimum number of distinct elements present in a K-length subsequence in an array Given an array A[] consisting of N integers and an integer K, the task is to count the minimum number of distinct elements present in a subsequence of length K of the given array, A. Examples: Input: A = {3, 1, 3, 2, 3, 4, 5, 4}, K = 4Output: 2Explanation: The subsequence of length 4 containing minimum number of distinct elements is {3, 3, 3, 4}, c 7 min read Length of longest subset consisting of A 0s and B 1s from an array of strings Given an array arr[] consisting of N binary strings, and two integers A and B, the task is to find the length of the longest subset consisting of at most A 0s and B 1s. Examples: Input: arr[] = {"1", "0", "0001", "10", "111001"}, A = 5, B = 3Output: 4Explanation: One possible way is to select the subset {arr[0], arr[1], arr[2], arr[3]}.Total number 15+ min read Length of longest subset consisting of A 0s and B 1s from an array of strings | Set 2 Given an array arr[] consisting of N binary strings, and two integers A and B, the task is to find the length of the longest subset consisting of at most A 0s and B 1s. Examples: Input: arr[] = {“1”, “0”, “0001”, “10”, “111001”}, A = 5, B = 3Output: 4Explanation: One possible way is to select the subset {arr[0], arr[1], arr[2], arr[3]}.Total number 13 min read Count K-length subarrays whose average exceeds the median of the given array Given an array arr[] consisting of N integers and a positive integer K, the task is to find the number of subarrays of size K whose average is greater than its median and both the average, median must be either prime or non-prime. Examples: Input: arr[] = {2, 4, 3, 5, 6}, K = 3Output: 2Explanation:Following are the subarrays that satisfy the given 9 min read Why Variable Length Array were Removed in C++? While historically a feature in the C language, the variable length array is not part of standard C++. This article discusses the C++'s approach to dynamic memory allocation, showing an alternative strategy employed to achieve a similar outcome. Variable Length ArrayThe Array is said to be a variable length array if the size is defined at the runti 3 min read What is the Max Array Length Limit in C++? In C++, arrays are data structures that store data of the same type in continuous memory locations. However, when working with arrays, it's important to be aware of certain limitations, including the maximum length of an array that can be declared. In this article, we will learn how we can find the maximum array length limit in C++ Max Array Length 2 min read Minimize flips on K-length subarrays required to make all array elements equal to 1 Given a binary array arr[] of size N and a positive integer K, the task is to find the minimum number of times any subarray of size K from the given array arr[] is required to be flipped to make all array elements equal to 1. If it is not possible to do so, then print "-1". Examples: Input: arr[] = {0, 1, 0}, K = 1Output: 2Explanation:Perform the o 15+ min read C++ Program to Find array sum using Bitwise OR after splitting given array in two halves after K circular shifts Given an array A[] of length N, where N is an even number, the task is to answer Q independent queries where each query consists of a positive integer K representing the number of circular shifts performed on the array and find the sum of elements by performing Bitwise OR operation on the divided array.Note: Each query begins with the original arra 5 min read Count unique subsequences of length K Given an array of N numbers and an integer K. The task is to print the number of unique subsequences possible of length K. Examples: Input : a[] = {1, 2, 3, 4}, k = 3 Output : 4. Unique Subsequences are: {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4} Input: a[] = {1, 1, 1, 2, 2, 2 }, k = 3 Output : 4 Unique Subsequences are {1, 1, 1}, {1, 1, 2}, {1, 2, 11 min read match_results length() in C++ STL The match_results::length() is a inbuilt function in C++ which is used to return the length of a particular match in the match_results object.Syntax: smatch_name.length(n) Note: smatch_name is an object of match_results class. Parameters: It accepts a single parameter n which specifies the Match number. It is lower than match_results::size. The mat 2 min read Check If every group of a's is followed by a group of b's of same length Given string str, the task is to check whether every group of consecutive a's is followed by a group of consecutive b's of the same length. If the condition is true for every group then print 1 else print 0. Examples: Input: str = "ababaabb" Output: 1 ab, ab, aabb. All groups are valid Input: str = "aabbabb" Output: 0 aabb, abb (A single 'a' follow 5 min read Area of a n-sided regular polygon with given side length Given a regular polygon of N sides with side length a. The task is to find the area of the polygon. Examples: Input : N = 6, a = 9 Output : 210.444 Input : N = 7, a = 8 Output : 232.571 Approach: In the figure above, we see the polygon can be divided into N equal triangles. Looking into one of the triangles, we see that the whole angle at the cente 4 min read Length of Diagonal of a n-sided regular polygon Given a n-sided regular polygon of side length a.The task is to find the length of it's diagonal.Examples: Input: a = 9, n = 10 Output: 17.119 Input: a = 4, n = 5 Output: 6.47213 Approach: We know that the sum of interior angles of a polygon = (n – 2) * 180 where, n is the no. of sides in the polygon. So, each interior angle = (n – 2) * 180/n Now, 4 min read Count all Prime Length Palindromic Substrings Given string str, the task is to count all the sub-strings of str which are palindromes and their length is prime. Examples: Input: str = "geeksforgeeks" Output: 2 "ee" and "ee" are the only valid sub-strings. Input: str = "abccc" Output: 3 Approach: Using Sieve of Eratosthenes, find all the primes till the length of str because that is the maximum 15 min read