Programming Articles

Page 502 of 2544

Best Sightseeing Pair in C++

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

Suppose we have an array A of positive integers, now A[i] represents the value of the i-th sightseeing spot, and two sightseeing spots i and j have distance j - i. Now the score of a pair (i < j) of sightseeing spots is follows this formula (A[i] + A[j] + i - j): We have to find the maximum score of a pair of sightseeing spots. So if the input is like [8, 1, 5, 2, 6], then the output will be 11, as i = 0, j = 2, the value of A[0] + A[2] + 0 – ...

Read More

scalbn() function in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 143 Views

In this article we will be discussing the working, syntax and examples of scalbn() function in C++ STL.What is scalbn()?scalbn() function is an inbuilt function in C++ STL, which is defined in the header file. scalbn() function is used to scale significantly using the floating point base exponent.Significand is a part of a floating-point number consisting of its significant digits, depending upon the interpretation of the exponent significand can be an integer or a fraction.The function calculates the product of num and FLT_RADIX to the power n, where FLT_RADIX is the base of all floating point data types and ...

Read More

Sum 2D array in Python using map() function

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 5K+ Views

In this tutorial, we are going to find the sum of a 2D array using map function in Python.The map function takes two arguments i.e., function and iterable. It passes every element of the iterable to the function and stores the result in map object. We can covert the map object into an iterable.Let's see how to find the sum of the 2D array using the map function.Initialize the 2D array using lists.Pass the function sum and 2D array to the map function.Find the sum of resultant map object and print it.ExampleSee the code below.# initializing the 2D array array ...

Read More

Wiggle Sort II in C++\\n

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

Suppose we have an unsorted array nums, we have to rearrange it such that nums[0] < nums[1] > nums[2] < nums[3]. So if the input is like [1, 5, 1, 1, 6, 4], then the output will be [1, 4, 1, 5, 1, 6].To solve this, we will follow these steps −make one array x, that has same elements as numssort x arrayi := size of x – 1, j := (size of x – 1) / 2 and n := size of nums arrayfor l in range 0 to n – 1, increase l by 2 in each stepnums[l] ...

Read More

mktime() function in C++ STL

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 789 Views

In this article we will be discussing the working, syntax and examples of mktime() function in C++ STL.What is mktime()?mktime() function is an inbuilt function in C++ STL, which is defined in the header file. mktime() function is used to convert the local time to and object time_t.This function is like the reverse of the function localtime(), which converts an input to the local timezone of the machine.This function automatically modifies the values of the member timeptr if they are off the range or there is tm_day and tm_yday which are not allowed.Syntaxtime_t mktime( struct tm* tptr );ParametersThe function ...

Read More

Maximum Product of Word Lengths in C++

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

Suppose we have a string array called words, find the maximum value of length(word[i]) * length(word[j]) where the two words will not share the common letters. We can assume that each word will contain only lower case letters. If no such two words exist, then return 0. So if the input is like [“abcw”, “baz”, “foo”, “bar”, “xtfn”, “abcdef”], then the output will be 16, as two words can be “abcw”, “xtfn”.To solve this, we will follow these steps −Define a method called getRev(), this will take x as inputret := 0for i in range 0 to 25if x / ...

Read More

Battleships in a Board in C++

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

Suppose we have an 2D board, we have to count how many battleships are in it. The battleships are represented with the symbol 'X', empty slots are represented with '.'s. We can assume these rules −You receive a valid board, made of only battleships or empty slots.Battleships can only be placed horizontally or vertically. In other words, they can only be made of the shape 1xN (1 row, N columns) or Nx1 (N rows, 1 column), where N can be of any size.At least one horizontal or vertical cell separates between two battleships - there are no adjacent battleships.So if ...

Read More

Integer Break in C++

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

Suppose we have a positive integer n, we have to break it into the sum of at least two positive numbers and maximize the product of those integers. We have to find the maximum product we can get. So if the number is 10, then the answer will be 36, as 10 = 3 + 3 + 4, 3 * 3 * 4 = 36To solve this, we will follow these steps −Define a method solve(), this will take n, array dp and flagif n is 0, then return 1if dp[n] is not -1, then return dp[n]end := n – ...

Read More

N-ary Tree Level Order Traversal in C++

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

Suppose we have an n-ary tree, we have to return the level order traversal of its nodes' values. The Nary-Tree input serialization is represented in their level order traversal. Here each group of children is separated by the null value (See examples). So the following tree can be represented as [1, null, 3, 2, 4, null, 5, 6]The output will be [[1], [3, 2, 4], [5, 6]]To solve this, we will follow these steps −make one matrix ansif root is null, return ansmake one queue q and insert rootwhile q is not emptysize := size of the queuemake one array ...

Read More

Binary String With Substrings Representing 1 To N in C++

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

Suppose we have a binary string S and a positive integer N, we have to say true if and only if for every integer X from 1 to N, the binary representation of X is a substring of the given S. So if S = “0110” and N = 3, then the result will be true, as 1, 10 and 11 all are present in 0110.To solve this, we will follow these steps −Define a method to convert(), that will take n as inputret := an empty stringwhile n is not 0ret := ret concatenate n mod 2n := n ...

Read More
Showing 5011–5020 of 25,433 articles
« Prev 1 500 501 502 503 504 2544 Next »
Advertisements