C++ Articles

Page 81 of 597

Longest Happy String in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 775 Views

Suppose there is a string. That string is called happy if it does not have any of the strings like 'aaa', 'bbb' or 'ccc' as a substring. If we have three integers like a, b and c, then return any string s, which satisfies the following conditions −s is happy and longest possible.s contains at most an occurrence of the letter 'a', at most b occurrences of the letter 'b' and at most c occurrences of the letter 'c'.s will only contain 'a', 'b' and 'c' letters.If there is no such string, then return an empty string.So, if the input ...

Read More

Queries on a Permutation With Key in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 234 Views

Suppose we have an array queries of positive integers between 1 and m, we have to process all queries, queries[i] (from i=0 to n, n is the size of queries - 1) according to the following rules −At the beginning, we have the permutation P=[1, 2, 3, ..., m].For the current i, find the position of queries[i] in the permutation P (indexing from 0) and then move this at the beginning of the permutation P.We have to find an array containing the result for the given queries.So, if the input is like queries = [3, 1, 2, 1], m = ...

Read More

Simplified Fractions in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 465 Views

Suppose we have an integer n, we have to find a list of all simplified fractions between 0 and 1 (exclusive) such that the denominator

Read More

HTML Entity Parser in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 832 Views

Suppose we have a string; we have to design one HTML parser that will replace the special character of HTML syntax into normal character. The HTML entity parser is the parser that takes HTML code as input and replace all the entities of the special characters by the characters itself. These are the special characters and their entities for HTML −Quotation Mark − the entity is " and symbol character is ".Single Quote Mark − the entity is ' and symbol character is '.Ampersand − the entity is & and symbol character is &.Greater Than Sign − the entity is ...

Read More

The k-th Lexicographical String of All Happy Strings of Length n in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 295 Views

Suppose we have a string. We will call that a happy string when it consists of only ['a', 'b', 'c'] letters, and s[i] != s[i + 1] for all values of i from 1 to length of s - 1 (here the string is 1-indexed).So, if we have two integers n and k, consider a list of all happy strings of length n sorted in lexicographical order. We have to find the the kth string of this list or return an empty string if there are less than k happy strings of length nSo, if the input is like n ...

Read More

Maximum Number of Vowels in a Substring of Given Length in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 654 Views

Suppose we have a string s and an integer k. We have to find the maximum number of vowel letters in any substring of s with length k.So, if the input is like s = "abciiidef", k = 3, then the output will be 3To solve this, we will follow these steps −cnt := 0Define one set mfor each vowel v, doinsert v into mret := 0for initialize i := 0, when i < k, update (increase i by 1), do −cnt := cnt + (1 when s[i] is in m, otherwise 0)ret := maximum of ret and cntn := ...

Read More

Display Table of Food Orders in a Restaurant in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 444 Views

Suppose we have an array orders, which represents the orders that customers have done in a restaurant. So, orders[i]=[cust_namei, table_numi, food_itemi] where cust_namei is the customer name, table_numi is the customers table number, and food_itemi is the item customer orders.We have to return the restaurant's “display table”. Here the “display table” is a table whose row entries denote how many of each food item each table ordered. The first column will be the table number and the remaining columns correspond to each food item in alphabetical order. First row should be a header whose first column is “Table”, followed by ...

Read More

Minimum Number of Frogs Croaking in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 357 Views

Suppose we have a string called croakOfFrogs, this represents a combination of the string "croak" from different frogs, multiple frogs can croak at the same time, so multiple "croak" are mixed. We have to find the minimum number of different frogs to finish all the croak in the given string.Here a valid "croak" means a frog is generating 5 letters ‘c’, ’r’, ’o’, ’a’, ’k’ sequentially. The frogs have to generate all five letters to finish a croak. If the string is not a valid "croak" string then return -1.So, if the input is like "crcoakroak", then the output will ...

Read More

Longest Substring with At Most Two Distinct Characters in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Suppose we have a string s; we have to find the length of the longest substring t that has at most 2 distinct characters.So, if the input is like "eceba", then the output will be 3 as t is "ece" which its length is 3.To solve this, we will follow these steps −Define a function lengthOfLongestSubstringKDistinct(), this will take s, k, ans := 0Define one map mn := size of s, x := 0for initialize j := 0, i := 0, when j < n, update (increase j by 1), do −(increase m[s[j]] by 1)if m[s[j]] is same as 1, ...

Read More

Maximum Points You Can Obtain from Cards in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 388 Views

Suppose there are several cards arranged in a row, each card has associated points, and these points are given in the integer array called cardPoints. In one step, we can take one card from the beginning or from the end of the row. We have to take exactly k cards. The final score will be the sum of the points of the cards we have taken. So, if we have integer array cardPoints and the integer k, then find the maximum score we can obtain.So, if the input is like cardPoints = [1, 2, 3, 4, 5, 6, 1], k ...

Read More
Showing 801–810 of 5,962 articles
« Prev 1 79 80 81 82 83 597 Next »
Advertisements