Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 98 of 377

Revolving Door in C++

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

Suppose we have a list of requests, where requests[i] contains [t, d] indicating at time t, a person arrived at the door and either wanted to go inside (inside is indicating using 1) or go outside (outside is indicating using 0).So if there is only one door and it takes one time unit to use the door, there are few rules that we have to follow −The door starts with 'in' position and then is set to the position used by the last participant.If there's only one participant at the door at given time t, they can use the door.If ...

Read More

Unique Fractions in C++

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

Suppose we have a list of fractions where each fraction contains [numerator, denominator] (numerator / denominator). We have ti find a new list of fractions such that the numbers in fractions are −In their most reduced terms. (20 / 14 becomes 10 / 7).Any duplicate fractions (after reducing) will be removed.Sorted in ascending order by their actual value.If the number is negative, the '-' sign will be with the numerator.So, if the input is like {{16, 8}, {4, 2}, {7, 3}, {14, 6}, {20, 4}, {-6, 12}}, then the output will be [[-1, 2], [2, 1], [7, 3], [5, 1]]To ...

Read More

Check if a key is present in every segment of size k in an array in Python

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

Suppose we have an array A with N elements, we have another value p and a segment size k, we have to check whether key p is present in every segment of size k in A.So, if the input is like A = [4, 6, 3, 5, 10, 4, 2, 8, 4, 12, 13, 4], p = 4 and k = 3, then the output will be TrueTo solve this, we will follow these steps −i := 0while i < n is non-zero, doj := 0while j < k, doif arr[j + i] is same as p, thenbreakj := j ...

Read More

TV Shows in C++

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

Suppose we have a list of TV shows, and another list of duration, and an integer k, here shows[i] and duration[i] shows the name and duration watched by the ith person, we have to find the total duration watched of the k most watched shows.So, if the input is like shows: ["Castle Play", "Fairy Tale Series", "Castle Play", "Jerry Mouse", "Rich Boy"], duration: [6, 4, 6, 14, 5] and k = 2, then the output will be 26.To solve this, we will follow these steps −Define one map mn := size of vfor initialize i := 0, when i < ...

Read More

Check if a king can move a valid move or not when N nights are there in a modified chessboard in Python

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

Suppose we have one infinite chessboard with the same rules as that of chess and if there are N knights coordinates on the infinite chessboard and the king’s coordinate, we have to check whether the King is checkmate or not. The coordinate of infinite board is bounded by large value like (-10^9

Read More

Minimum String in C++

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

Suppose we have two strings s and t of same length, and both are in lowercase letters. Consider we have rearranged s at first into any order, then count the minimum number of changes needed to turn s into t.So, if the input is like s = "eccynue", t = "science", then the output will be 2 as if we rearrange "eccynue" to "yccence", then replace y with s and second c with i, it will be "science".To solve this, we will follow these steps −ret := 0Define two arrays cnt1 to hold frequency of s and cnt2 to hold ...

Read More

Where is an object stored if it is created inside a block in C++?

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

In this section we will discuss about where the variables and objects are stored in the memory when a C++ program is compiled. As we know, there are two parts of memory in which an object can be stored −Stack − All members that are declared inside block of memory, it stores inside the stack section. The main function is also a function, so elements inside it will be stored inside the stack.Heap − When some objects are allocated dynamically, then that is stored inside the heap section.The scope of the object declared inside a block or a function is ...

Read More

Cha Cha Slide C++

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

Suppose we have two strings s and t. we have to check whether s is rotation of t or not, in other words, can we get t after rotating s?So, if the input is like s = "helloworld" and t = "worldhello", then the output will be True.To solve this, we will follow these steps −if size of s0 is not equal to size of s1, then −return falses := s0 concatenate s0return true when s1 is in s, otherwise 0Let us see the following implementation to get better understanding −Example#include using namespace std; class Solution {    public: ...

Read More

Check if a number is a Trojan Numbers in Python

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

Suppose we have a number n, we have to check whether n is a Trojan Number or not. As we know that the Trojan Number is a number that is a strong number without a perfect power. A number n is a strong number when for every prime divisor or factor p of n, p^2 is also a divisor. In other words, every prime factor appears at least twice. Trojan numbers are strong. But the reverse is not true. So it means, not all strong numbers are Trojan numbers: only those that cannot be represented as a^b.So, if the input ...

Read More

Compress String in C++

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

Suppose we have a string s, we have to eliminate consecutive duplicate characters from the given string and return it. So, if a list contains consecutive repeated characters, they should be replaced with a single copy of the character. The order of the elements will be same as before.So, if the input is like "heeeeelllllllloooooo", then the output will be "helo"To solve this, we will follow these steps −ret := a blank stringfor initialize i := 0, when i < size of s, update (increase i by 1), do −if size of ret is non-zero and last element of ret ...

Read More
Showing 971–980 of 3,768 articles
« Prev 1 96 97 98 99 100 377 Next »
Advertisements