Found 1862 Articles for Data Structure

Given a Number N in Decimal Base, find Number of its Digits in any Base (base b)

Rinish Patidar
Updated on 28-Aug-2023 15:25:51

133 Views

The problem statement includes finding the number of digits in N when represented in any base b numeral system. Initially, N is given in the base−10 numeral system. In the problem, we will be provided with a positive integer N in the input which will be in the base−10 numeral system and a positive integer b greater than 1. Our task will be to find the number of digits when N is being represented in the base−b numeral system. Any number represented in any base number, every digit from right represents the number of times power of that base number ... Read More

Count Numbers formed by given two Digit with Sum having given Digits

Rinish Patidar
Updated on 28-Aug-2023 15:23:19

94 Views

The problem statement includes counting the numbers formed by the given two digits, x and y of size N with sum having given digits only i.e. x and y. We need to count the distinct numbers which can be formed by the digits, x and y which will be the user input of size N where N ranges from 1 to 10^6. The N will also be provided in the input. The numbers formed using the digits, x and y of size N must be such that the sum of digits of the numbers formed should have only digits ... Read More

Frequency Measuring Techniques for Competitive Programming

Avinash Gupta
Updated on 28-Aug-2023 18:17:21

172 Views

In this article, we are going to find the different ways to find the frequency of numbers present in an array []. These methods are very useful in doing competitive programming for different problems for different cases. Sometimes, calculating the frequency of elements whether it is numbers or alphabets presented in the array is a complicated task. Various algorithms like Searching, array, divide and conquer can be used to find the repeated elements defined in the array. Note- Take an integer array. Let's explore the article, to know how it can be solved by using Java programming ... Read More

Smallest string divisible by two given Strings

Vanshika Sood
Updated on 27-Oct-2023 16:00:53

750 Views

The objective of this article is to determine the smallest string that is a multiple of both given strings. An interesting observation to note is that for two given strings s and t, the string s is a multiple of t if and only if s can be formed by repeating t one or more times. We have to find the smallest such string. Problem Statement Given two non-empty strings, s1 and s2, with lengths n and m respectively, the objective is to determine the smallest string that is a multiple of both s1 and s2. A ... Read More

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

Vanshika Sood
Updated on 27-Aug-2023 11:39:30

59 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
Updated on 27-Aug-2023 11:35:53

116 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
Updated on 27-Aug-2023 11:24:27

235 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

Lexicographically largest string possible by repeatedly appending first character of two given strings

Vanshika Sood
Updated on 27-Aug-2023 10:07:19

158 Views

Lexicographic ordering refers to a method of comparing sequences of elements, akin to the ordering of words in a dictionary. The comparison process involves evaluating the first element of each sequence. If the first element of the first sequence is considered smaller than the first element of the second sequence, the first sequence is considered lexicographically less than the second sequence. Conversely, if the first element of the first sequence is deemed larger than the first element of the second sequence, the first sequence is lexicographically greater than the second sequence. Problem Statement The objective is to generate ... Read More

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

Vanshika Sood
Updated on 27-Aug-2023 09:57:29

187 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
Updated on 27-Aug-2023 09:54:43

89 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

Advertisements