Data Structure Articles

Page 30 of 164

Nearest power of 2 of frequencies of each digit of a given number

Vanshika Sood
Vanshika Sood
Updated on 27-Aug-2023 242 Views

The article describes a method to calculate the closest power of 2 for the frequency of each digit in a given number. The term "frequencies" refers to the count of occurrences of each unique digit in the number. Problem Statement Determine the occurrence count of each digit in a positive integer N. Then, for each digit, find the nearest power of 2 to its frequency. If there are two nearest powers of 2 for any frequency, print the larger one. Example Input n = 677755 Output 5 -> 2 6 -> 1 7 -> 4 ...

Read More

Maximize count of occurrences of S2 in S1 as a subsequence by concatenating N1 and N2 times respectively

Vanshika Sood
Vanshika Sood
Updated on 27-Aug-2023 426 Views

The following article discusses an approach to count the maximum occurrences of a string s2 in another string s1 after they have been concatenated N1 and N2 times respectively. This is an interesting type of pattern searching problem. In this article we have employed a relatively intuitive solution approach. Problem Statement The task is to determine the maximum number of non-overlapping occurrences of string s2 within string s1. The strings are concatenated multiple times: s1 is repeated n1 times, and s2 is repeated n2 times. Example Input s1 = “abc”, s2 = “ac”, n1 = 4, n2 ...

Read More

Lexicographically smallest string with period K possible by replacing ‘?’s from a given string

Vanshika Sood
Vanshika Sood
Updated on 27-Aug-2023 451 Views

A string is a period of K if and only if it repeats itself every K characters. For example, the string "abcabcabc" is a period of 3, because it repeats itself every 3 characters. The string "abcabc?abc" is not a period of 3, because the character '?' does not repeat itself every 3 characters. Problem Statement Given a string "str" containing N lowercase characters and a positive integer K, the objective is to replace every occurrence of the character '?' within the string "str" with a lowercase alphabet such that the resulting string forms a period of length ...

Read More

Count all prime numbers that can be formed using digits of a given number

Vanshika Sood
Vanshika Sood
Updated on 27-Aug-2023 581 Views

Any number larger than 1 is said to be prime if it cannot be written as the product of two smaller natural numbers except 1 and the number itself. For instance, 5 is prime since its only product forms, 1 5 and 5 1, both involve 5. Primes play a crucial role in number theory as stated by the prime number theorem, which asserts that any natural number greater than 1 is either a prime itself or can be expressed as a unique product of prime numbers. This theorem highlights the significance of prime numbers in the realm of mathematics. ...

Read More

Calculate time required to type a word using given single-row keyboard

Vanshika Sood
Vanshika Sood
Updated on 27-Aug-2023 318 Views

The following article discusses an efficient approach to compute the total time taken to type out a word using a single-row keyboard. This is an interesting problem and has been asked previously in technical interviews. Problem Statement Consider a hypothetical scenario wherein all the keys on a keyboard are placed in a single row. The first key is indexed 0 and the last key is indexed 25. For a given string ‘s’ calculate the time taken to type all the characters of ‘s’ on a special keyboard with layout specified as ‘keyboard_layout’. The time taken ...

Read More

Find Mth Eelement after K Right Rotations of an Array

Vanshika Sood
Vanshika Sood
Updated on 27-Aug-2023 202 Views

Right rotating an array means shifting its elements to the right by a certain number of positions. In a single right rotation, the last element of the array becomes the first element, and the remaining elements are shifted to the right. Problem Statement The goal is to find the Mth element of an array after performing K right rotations, where K and M are non-negative integers and the array contains N elements. Sample Examples Input arr = [12 34 56 21], K = 2, M = 1 Output 56 Explanation Arr after K right ...

Read More

Reconstruct original string from resultant string based on given encoding technique

Shubham Vora
Shubham Vora
Updated on 25-Aug-2023 205 Views

In this problem, we need to construct the original string from the given string. The given string is formed from the original string using the given rules. Here, we can use the given encryption rule and encrypted string to find the decrypted string by applying the encryption rule in reverse order. Problem statement – We have given a binary string bin_str of length N and positive integer k. The binary string is constructed from the ‘enc’ string by following the below operations and using the x value. If enci-k is equal to 1, bin_stri is equal to 1. If ...

Read More

Minimum Characters to be Replaced in given String to make all Characters Same

Shubham Vora
Shubham Vora
Updated on 25-Aug-2023 454 Views

In this problem, we will find a minimum number of string characters needed to be replaced to make all characters. In the first approach, we will find the minimum count of the replaceable characters by counting the frequency of each character in the given string. In another approach, we will determine the cost to convert all string characters to a particular character and take the minimum value from that. Problem statement – We have given a string alpha containing N alphabetical characters. We need to find the minimum number of characters to replace to make all string characters equal. Sample ...

Read More

Minimize Partitions in given String to get Another String

Shubham Vora
Shubham Vora
Updated on 25-Aug-2023 195 Views

In this problem, we need to construct one string by slicing the other string. We can use the longest common substring to solve the problem. We can find the longest common substring between both strings, slice str1 into 1 or 2 parts, and remove the substring from str2. Again, we find the longest common substring in updated strings and follow it until str2 becomes empty. In this way, we can solve the problem. Problem statement – We have given str1 and str2 strings of different lengths. We need to construct the string str2 by slicing and concatenating the parts of ...

Read More

Lexicographically Smallest String formed by Concatenating any prefix and its Mirrored form

Shubham Vora
Shubham Vora
Updated on 25-Aug-2023 297 Views

In this problem, we will find the lexicographically smallest string by concatenating the given string’s prefix and its reverse. We can find the lexicographically smallest prefix of the string and get the required string. Problem statement – We have given a string alpha containing the alphabetical characters. We need to construct the lexicographically smallest string, which we can get by concatenating any string prefix with its reverse. Sample examples Input alpha = "welcome"; Output 'wewe’ Explanation – The lexicographically smallest prefix is ‘we’. So, we have concatenated it with its mirror. Input alpha = "tutorialspoint" ...

Read More
Showing 291–300 of 1,635 articles
« Prev 1 28 29 30 31 32 164 Next »
Advertisements