Articles on Trending Technologies

Technical articles with clear explanations and examples

Program to find maximum k-repeating substring from sequence in Python

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

Given a sequence of characters s, we say a string w is k-repeating if w concatenated k times is a substring of the sequence. The maximum k-repeating value of w is the highest value of k where w is k-repeating in the sequence. If w is not a substring of s, its maximum k-repeating value is 0. Problem Statement Given a sequence s and a string w, we need to find the maximum k-repeating value of w in the sequence. For example, if s = "papaya" and w = "pa", the output will be 2 because "pa" ...

Read More

Program to check whether two string arrays are equivalent or not in Python

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

Suppose we have two string arrays word1 and word2, we need to check whether they represent the same string when their elements are concatenated in order. A string can be represented by an array if concatenating all elements in that array forms the original string. So, if the input is like word1 = ["ko", "lka", "ta"] and word2 = ["k", "olk", "at", "a"], then the output will be True as both arrays form "kolkata" when concatenated. Approach To solve this, we will follow these steps: Initialize two empty strings s1 and s2 ...

Read More

Program to decrypt code to defuse the bomb in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 737 Views

Suppose there is a bomb that you are going to defuse, and your time is running out! You have a circular array code of length n and have a key k. To decrypt the code, you must replace every number simultaneously based on these rules ? If k > 0 then replace ith number with the sum of next k numbers. If k < 0 then replace ith number with the sum of previous k numbers. If k = 0 then replace ith number with 0. ...

Read More

Program to find maximum in generated array in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 538 Views

Given a number n, we need to generate an array A of length n + 1 using specific rules and find the maximum value in it. Array Generation Rules The array is built following these rules ? A[0] = 0 A[1] = 1 A[2 * i] = A[i] if 2 ≤ 2 * i ≤ n A[2 * i + 1] = A[i] + A[i + 1] if 2 ≤ 2 * i + 1 ≤ n Example Walkthrough For n = 5, let's see how the array is constructed ? ...

Read More

Program to check we can form array from pieces or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 281 Views

Suppose we have an array nums where all elements are unique and have another array with different smaller arrays called pieces. We have to check whether we can get the main array nums by concatenating the arrays in pieces in any order or not. But we are not allowed to reorder the elements present in each array pieces[i]. So, if the input is like nums = [5, 1, 12, 36, 2, 47, 6] pieces = [[2, 47, 6], [12, 36], [1], [5]], then the output will be True because we can concatenate them in this order [[5], [1], [12, ...

Read More

Program to sort array by increasing frequency of elements in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 2K+ Views

Suppose we have an array with some elements where elements may appear multiple times. We have to sort the array such that elements are sorted according to their increasing frequency. Elements that appear fewer times will come first, and when frequencies are equal, larger elements come first. So, if the input is like nums = [1, 5, 3, 1, 3, 1, 2, 5], then the output will be [2, 5, 5, 3, 3, 1, 1, 1] Algorithm Steps To solve this, we will follow these steps ? Create a frequency map to count occurrences of ...

Read More

Program to find largest substring between two equal characters in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 336 Views

Suppose we have a string s, we have to find the length of the longest substring between two equal letters or elements, excluding the two characters. If we cannot find such substring, then return -1. So, if the input is like s = "level", then the output will be 3 as optimal substrings can be either "lev" or "vel". Algorithm To solve this, we will follow these steps − memo := a new map for i in range 0 to size of s - 1, do if s[i] is in memo, then insert ...

Read More

Program to find mean of array after removing some elements in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 387 Views

Suppose we have an array called nums, we have to find the mean of the remaining values after removing the smallest 5% and the largest 5% of the elements. So, if the input is like nums = [2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8], then the output will be 4.0 because after removing smallest and largest values, all remaining elements are the same. Algorithm To solve this problem, we will follow these steps − Sort the array nums n := size of ...

Read More

Program to find X for special array with X elements greater than or equal X in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 590 Views

A special array is one where there exists a number x such that exactly x elements in the array are greater than or equal to x. We need to find this value x, or return -1 if no such value exists. For example, in the array [4, 6, 7, 7, 1, 0], there are 4 numbers (4, 6, 7, 7) that are greater than or equal to 4, making x = 4 the special value. Algorithm To solve this problem, we follow these steps ? Iterate through all possible values of ...

Read More

Program to design parking system in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 3K+ Views

Suppose you want to design a parking system. A parking lot has three different kinds of parking spaces − big, medium, and small. Each size has a fixed number of available slots. We'll create a class called ParkingSystem with two methods ? constructor(big, medium, small) − Takes the number of slots available for different spaces and initializes the ParkingSystem object. addCar(carType) − Checks whether there is a parking space of the given carType for the car that wants to park. The three slot types big, medium, and small are represented by 1, 2, and 3 respectively. ...

Read More
Showing 4711–4720 of 61,299 articles
« Prev 1 470 471 472 473 474 6130 Next »
Advertisements