Program to find nearest time by reusing same digits of given time in python

Arnab Chakraborty
Published on 26-Nov-2020 12:51:20
Suppose we have a 24-hour string in "hh:mm" format, we have to find the next closest time that can be formed by reusing given digits. We can reuse digits from the given string as many times as we want.So, if the input is like s = "03:15", then the output ... Read More

Program to find minimum number of days to wait to make profit in python

Arnab Chakraborty
Published on 26-Nov-2020 12:46:09
Suppose we have a list of prices representing the daily stock market prices of a company in chronological sequence. We have to find a same length list where the value at index i will be the minimum number of days we would have to wait until we make a profit. ... Read More

Program to find all possible strings typed using phone keypad in python

Arnab Chakraborty
Published on 26-Nov-2020 12:44:00
Suppose we have a string containing digits from 2-9. We have to find all possible letter combinations that the number could generate. One mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does map some characters but no letters.12a b c3d e ... Read More

Program to check whether a board is valid N queens solution or not in python

Arnab Chakraborty
Published on 26-Nov-2020 12:41:42
Suppose we have a n x n matrix represents a chess board. There are some 1s and 0s, where 1 represents a queen and 0 represents an empty cell. We have to check whether the board is valid solution to the N-Queen puzzle or not. As we know a board ... Read More

Program to check whether we can unlock all rooms or not in python

Arnab Chakraborty
Published on 26-Nov-2020 12:37:44
Suppose we have a list of lists called rooms. Each index i in rooms represents a room and rooms[i] represents different keys to open other rooms. The room 0 is open and we are at that room and every other room is locked. We can move freely between opened rooms; ... Read More

Program to find nth ugly number in C++

Arnab Chakraborty
Published on 26-Nov-2020 12:35:16
Suppose we have a number n; we have to find the nth ugly number. As we know that the ugly numbers are those numbers, whose prime factors are only 2, 3 and 5. So if we want to find 10th ugly number, the output will be 12, as the first ... Read More

Program to find median of two sorted lists in C++

Arnab Chakraborty
Published on 26-Nov-2020 12:25:56
Suppose we have two sorted lists. We have to find the median of these two lists. So if the arrays are like [1, 5, 8] and [2, 3, 6, 9], then the answer will be 5.To solve this, we will follow these steps:Define a function solve(), this will take an ... Read More

Program to generate tree using preorder and inorder traversal in python

Arnab Chakraborty
Published on 26-Nov-2020 12:20:57
Suppose we have the preorder and inorder traversal of a binary tree. We have to recover the tree from these sequences. So if the preorder and inorder sequences are [3, 9, 20, 15, 7] and [9, 3, 15, 20, 7], then the tree will be:Let us see the steps:Define a ... Read More

Program to check whether given list of blocks are symmetric over x = y line or not in python

Arnab Chakraborty
Published on 26-Nov-2020 12:18:08
Suppose we have a list of numbers called nums. And it is representing the height of square blocks, we have to check whether the shape is symmetric over the y = x line or not.So, if the input is like nums = [7, 5, 3, 2, 2, 1, 1], then ... Read More

Program to count number of consecutive lists whose sum is n in C++

Arnab Chakraborty
Published on 26-Nov-2020 12:15:20
Suppose we have a number n, we have to find the number of lists of positive consecutive values that sum up to n.So, if the input is like n = 15, then the output will be 4, as The possible lists are: [1, 2, 3, 4, 5], [4, 5, 6], ... Read More
Advertisements