Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 100 of 377

Generating Test Cases (generate() and generate_n() in C++

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

In this section we will see how we can use C++ STL function to generate test cases. Sometimes generating test cases for array programs can be very complicated and inefficient process. C++ provides two methods to generate test cases. These methods are as follows −The generate() methodThe C++ function std::algorithm::generate() assigns the value returned by successive calls to gen to the elements in the range of first to last. It takes three parameters first, last and gen, these are forward iterator to the initial position, backward iterator to the final position and generator function that is called with no argument, ...

Read More

Shortest Majority Substring in C++

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

Suppose we have a lowercase alphabet string s, we have to find the length of the shortest substring (minimum length is 2) such that some letter appears more than the other letters combined. If we cannot find any solution, then return -1.So, if the input is like "abbbcde", then the output will be 2, the substring "bb" has minimum length and this appears more than other letters.To solve this, we will follow these steps −Define a function ok(), this will take an array cnt, total := 0, maxVal := 0for each element it in cnt, dototal := total + itmaxVal ...

Read More

Geometry using Complex Numbers in C++

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

In this section, we will see how to make point class using complex class from STL in C++. And apply them on some geometry related problems. The complex number is present inside the complex class from STL (#include )Defining Point ClassTo make complex to point, we will change the name of the complex as point, then change x to real() of complex class and y to imag() of complex class. Thus, we can simulate the point class.# include typedef complex point; # define x real() # define y imag()We have to keep in mind that the x and y ...

Read More

123 Number Flip in Python

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

Suppose we have an integer n, where only 1, 2, and 3 these digits are present. We can flip one digit to a 3. Then find the maximum number we can make.So, if the input is like 11332, then the output will be 31332To solve this, we will follow these steps −li := a list by digits of nfor x in range 0 to size of li - 1, doif li[x] is not '3', thenli[x] := '3'return the number by merging digits from lireturn nLet us see the following implementation to get better understanding −Exampleclass Solution:    def solve(self, n): ...

Read More

Heap in C++ STL - make_heap(), push_heap(), pop_heap(), sort_heap(), is_heap, is_heap_until()

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

In this section we will see the heap data structure present in C++ STL. This permits faster input into heap and retrieval of a number always results in the largest number i.e. largest number of the remaining numbers is popped out each time. Other elements of the heap are arranged which depends on the implementation. The heap operations are as follows −make_heap() − This converts a range in a container to a heap.front() − This returns first element of heap which is the largest number.ExampleLet us see the following implementation to get better understanding −#include using namespace std; int main() ...

Read More

24-hour time in Python

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

Suppose we have a string s. Here s is representing a 12-hour clock time with suffixes am or pm, we have to find its 24-hour equivalent.So, if the input is like "08:40pm", then the output will be "20:40"To solve this, we will follow these steps −hour := (convert the substring of s [from index 0 to 2] as integer) mod 12minutes := convert the substring of s [from index 3 to 5] as integerif s[5] is same as 'p', thenhour := hour + 12return the result as hour:minutesLet us see the following implementation to get better understanding −Exampleclass Solution:   ...

Read More

3-6-9 in Python

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

Suppose we have a number n, we have to construct a list with each number from 1 to n, except when it is multiple of 3 or has a 3, 6, or 9 in the number, it should be the string "no-fill".So, if the input is like 20, then the output will be ['1', '2', 'clap', '4', '5', 'clap', '7', '8', 'clap', '10', '11', 'clap', 'clap', '14', 'clap', 'clap', '17', 'clap', 'clap', '20']To solve this, we will follow these steps −string := "no-fill"ls:= make a list of numbers as string from 1 to nfor i in range 0 to size ...

Read More

Uniform Initialization in C++

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

Here we will discuss about the uniform initialization in C++. This is supported from C++11 version. The uniform initialization is a feature that permits the usage of a consistent syntax to initialize variables and objects which are ranging from primitive type to aggregates. In other words, it introduces brace-initialization that applies braces ({}) to enclose initializer values.Syntaxtype var_name{argument_1, argument_2, .... argument_n}Initialize Dynamically allocated arraysExample (C++)Let us see the following implementation to get better understanding −#include using namespace std; int main() {    int* pointer = new int[5]{ 10, 20, 30, 40, 50 };    cout

Read More

3 and 7 in Python

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

Suppose we have a positive number n, we have to find that we can make n by summing up some non-negative multiple of 3 and some non-negative multiple of 7 or not.So, if the input is like 13, then the output will be True, as 13 can be written as 1*7+2*3 = 13To solve this, we will follow these steps −for i in range 0 to n+1, increase by 7, doif n-i is divisible by 3, thenreturn Truereturn FalseLet us see the following implementation to get better understanding −Exampleclass Solution:    def solve(self, n):       for i in ...

Read More

User Defined Literals in C++

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

Here we will see the concept of the user-defined literals in C++. From C++ version 11, the User Defined Literals (UDL) are added in C++. C++ also provides literals for a variety of built-in types but these are limited.Built-in Literals −31 (Integer)3.5 (Double)4.2F (Float)'p' (Character)31ULL (Unsigned Long Long)0xD0 (Unsigned Hexadecimal Integer)"pq" (String)Apart from the built-in literals, sometimes we need user defined literals. There are few reasons behind that. Let us see with few examples −Suppose we want to define one weight variable, but we cannot specify the units, like if we define as follows −long double Weight = 3.5;We have ...

Read More
Showing 991–1000 of 3,768 articles
« Prev 1 98 99 100 101 102 377 Next »
Advertisements