Articles on Trending Technologies

Technical articles with clear explanations and examples

Find k'th character of decrypted string in C++

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

Suppose we have one encoded string, where repetitions of substrings are represented as substring followed by count of substrings. So if the string is like ab2cd2, it indicates ababcdcd, and if k = 4, then it will return kth character, that is b here.To solve this, we initially take empty decrypted string then decompress the string by reading substring and its frequency one by one. Then append current substring in the decrypted string by its frequency. We will repeat this process till the string has exhausted, and print the Kth character from decrypted string.Example#include using namespace std; char findKthCharacter(string str, ...

Read More

Epoch time in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 10K+ Views

You can use the time() function in Perl to get epoch time, i.e., the numbers of seconds that have elapsed since a given date, in Unix is January 1, 1970.Example#!/usr/local/bin/perl $epoc = time(); print "Number of seconds since Jan 1, 1970 - $epoc";OutputWhen the above code is executed, it produces the following result −Number of seconds since Jan 1, 1970 - 1361022130You can convert a given number of seconds into date and time string as follows −Example#!/usr/local/bin/perl $datestring = localtime(); print "Current date and time $datestring"; $epoc = time(); $epoc = $epoc - 24 * 60 * 60;    # ...

Read More

POSIX Function strftime() in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 17K+ Views

You can use the POSIX function strftime() in Perl to format the date and time with the help of the following table. Please note that the specifiers marked with an asterisk (*) are locale-dependent.SpecifierReplaced byExample%aAbbreviated weekday name *Thu%AFull weekday name *Thursday%bAbbreviated month name *Aug%BFull month name *August%cDate and time representation *Thu Aug 23 14:55:02 2001%CA year divided by 100 and truncated to integer (00-99)20%dDay of the month, zero-padded (01-31)23%DShort MM/DD/YY date, equivalent to %m/%d/%y08/23/01%eDay of the month, space-padded ( 1-31)23%FShort YYYY-MM-DD date, equivalent to %Y-%m-%d2001-08-23%gWeek-based year, last two digits (00-99)01%GWeek-based year2001%hAbbreviated month name * (same as %b)Aug%HAn hour in 24h ...

Read More

Find maximum in stack in O(1) without using additional stack in C++

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

Suppose we want to make a stack that can store the maximum element in the stack. And we can get it in O(1) time. The constraint is that, it should not use any additional space, so O(1) extra space.We can make one user-defined stack, that will store the max value, when one operation is performed, like pop or peek, then the max will be returned. For peek operation, return the maximum of stack top and the max element, for pop operation, when the top element is larger, then print it and update max as 2*max – top_element. otherwise return top_element. ...

Read More

Define and Call a Subroutine in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 395 Views

The general form of a subroutine definition in Perl programming language is as follows −sub subroutine_name {    body of the subroutine }The typical way of calling that Perl subroutine is as follows −subroutine_name( list of arguments );In versions of Perl before 5.0, the syntax for calling subroutines was slightly different as shown below. This still works in the newest versions of Perl, but it is not recommended since it bypasses the subroutine prototypes.&subroutine_name( list of arguments );Let's have a look into the following example, which defines a simple function and then call it. Because Perl compiles your program before ...

Read More

Passing Arguments to a Subroutine in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 2K+ Views

You can pass various arguments to a Perl subroutine like you do in any other programming language and they can be accessed inside the function using the special array @_. Thus the first argument to the function is in $_[0], the second is in $_[1], and so on.You can pass arrays and hashes as arguments like any scalar but passing more than one array or hash normally causes them to lose their separate identities. So we will use references ( explained in the next chapter ) to pass an array or hash.Let's try the following example, which takes a list ...

Read More

Find minimum number of currency notes and values that sum to given amount in C++

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

Suppose we have such amount, and we have to find the minimum number of notes of different denominations, that sum up to the given amount. Start from highest denomination notes, try to find as many notes possible for given amount. Here the assumption is that we have infinite amount of {2000, 500, 200, 100, 50, 20, 10, 5, 2, 1}. So if the amount is say 800, then notes will be 500, 200, 100.Here we will use the greedy approach to solve this problem.Example#include using namespace std; void countNotes(int amount) {    int notes[10] = { 2000, 500, 200, 100, ...

Read More

Passing Lists to Subroutines in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 1K+ Views

Because the @_ variable is an array in Perl, it can be used to supply lists to a subroutine. However, because of the way in which Perl accepts and parses lists and arrays, it can be difficult to extract the individual elements from @_. If you have to pass a list along with other scalar arguments, then make list as the last argument as shown below −Example#!/usr/bin/perl # Function definition sub PrintList {    my @list = @_;    print "Given list is @list"; } $a = 10; @b = (1, 2, 3, 4); # Function call with list parameter ...

Read More

Find profession in a special family in C++

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

Consider there is a special family of doctors and engineers. There are some rules, these are like below −Everybody has two childrenFirst child of an engineer is an engineer, second child is doctorFirst child of a doctor is a doctor, second child is an engineerAll generations of doctors and engineers starts with engineerSo if we want to get result for level 4 and pos 2, then result will be DoctorThe idea is simple. Profession of a person depends on following two.Profession of the parent.Position of node: When the position of a node is odd, then its profession is same as ...

Read More

Passing Hashes to Subroutines in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 2K+ Views

When you supply a hash to a Perl subroutine or operator that accepts a list, then the hash is automatically translated into a list of key/value pairs. For example −Example#!/usr/bin/perl # Function definition sub PrintHash {    my (%hash) = @_;    foreach my $key ( keys %hash ) {       my $value = $hash{$key};       print "$key : $value";    } } %hash = ('name' => 'Tom', 'age' => 19); # Function call with hash parameter PrintHash(%hash);OutputWhen the above program is executed, it produces the following result −name : Tom age : 19

Read More
Showing 28621–28630 of 61,299 articles
Advertisements