Programming Articles

Page 471 of 2544

Queue Reconstruction by Height in C++

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

Consider we have a random list of people standing in a queue. If each person is described by a pair of integers (h, k), where h is the height and k is the number of people in front of him, who have a height greater than or equal to h. We have to define one method to reconstruct the queue. So if the given array is like [[7, 0], [4, 4], [7, 1], [5, 0], [6, 1], [5, 2]], then the output will be [[5, 0], [7, 0], [5, 2], [6, 1], [4, 4], [7, 1]]To solve this, we will ...

Read More

How to find PHP execution time?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 347 Views

In PHP version 7+, the getrusage function can be used. Below is a sample code demonstration −Example//beginning of the script $exec_start = getrusage(); //other code functionalities //end of the script function rutime($ru, $rus, $index) {    return ($ru["ru_$index.tv_sec"]*1000 + intval($ru["ru_$index.tv_usec"]/1000))    - ($rus["ru_$index.tv_sec"]*1000 + intval($rus["ru_$index.tv_usec"]/1000)); } $ru = getrusage(); echo "The process used " . rutime($ru, $exec_start, "utime") .    " ms for the computations"; echo "Spent " . rutime($ru, $exec_start, "stime") .    " ms during system calls";Note − There is no need to calculate the time difference if a php instance is spawned for every test.OutputThis will produce ...

Read More

How can I remove all empty values when I explode a string using PHP?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

The array_filter() or PREG_SPLIT_NO_EMPTY option on preg_split() can be used to remove empty values from a string when it is exploded −Example

Read More

Modulus function in C++ STL

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 4K+ Views

In this article, we will be discussing the working, syntax, and examples of modulus functions in C++.What is modulus function C++?modulus function object class in C++, which is defined in header file. modulus function is a binary function object class used to get the result of the modulus operation of the two arguments. This function works the same as the operator ‘% ‘.Syntax of modulus functionTemplate struct modulus : binary_function {    T operator() (const T& a, const T& b) const {return a%b; } };Template parametersThe function accepts the following parameter(s) −T − This is the type of the ...

Read More

Partition Equal Subset Sum in C++

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

Suppose we have a non-empty array containing only positive numbers, we have to find if the array can be partitioned into two subsets such that the sum of elements in both subsets is the same. So if the input is like [1, 5, 11, 5], the output will be true. As this array can be partitioned as [1, 5, 5] and [11]To solve this, we will follow these steps −n := size of the arraysum := 0for i := 0 to n – 1sum := sum + nums[i]if sum is odd, return falsesum := sum / 2create one array called ...

Read More

Word Ladder in C++

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

Suppose we have two words (beginWord and endWord), and we have dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that −Only one letter can be converted at a time.In each transformed word must exist in the word list. The beginWord is not a transformed word.We have to keep in mind that −Return 0 when there is no such change sequence.All words have the same length.All words contain only lowercase characters.We can assume no duplicates in the word list.So if the input is like: beginWord = "hit", endWord = "cog", and wordlist = ["hot", ...

Read More

Detect base64 encoding in PHP?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 734 Views

To detect base64 encoding in PHP, the code is as follows −Example

Read More

Raw string literal in C++ program

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

In this article, we will be discussing the raw string literal in C++, its meaning, and examples.There are escape characters in C++ like “” or “\t”. When we try to print the escape characters, it will not display on the output. To show the escape characters on the output screen we use a raw string literal by using R”(String with escape characters)”. After using R in the front of the string the escape character will be displayed on the output.ExampleLet’s understand this with the help of an example#include using namespace std; int main(){    string str = "tutorialspoint" ; ...

Read More

Prime or not in Python

Pradeep Elance
Pradeep Elance
Updated on 11-Mar-2026 808 Views

Prime numbers play a central role in many e it applications like cryptography. So it is a necessity to check for prime numbers using Python programs in various applications. A prime number is a number which doesn't have any factors other than one and itself. Below will see programs that can find out if a given number is prime or not.ApproachWe take the following approach to decide whether a number is prime or not.Check at the beginning is positive or not. As only positive numbers can be prime numbers.We divide the number with all the numbers in the range of ...

Read More

Reconstruct Original Digits from English in C++

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

Suppose we have a non-empty string containing an out-of-order English representation of digits 0-9, output the digits in ascending order. There are some properties −Input is guaranteed to be valid and can be transformed to its original digits. That means invalid inputs such as "abc" or "zerone" are not permitted.Input length is less than 50, 000.So if the input is like “fviefuro”, then the output will be 45.To solve this, we will follow these steps −nums := an array that is holding the numbers in English letter from 0 to 9.make one array count of size 10ans := an empty ...

Read More
Showing 4701–4710 of 25,433 articles
« Prev 1 469 470 471 472 473 2544 Next »
Advertisements