Program to convert a string to zigzag string of line count k in python

Arnab Chakraborty
Published on 26-Nov-2020 13:03:24
Suppose we have a string s and another value k, We have to find a new string by taking each character from s and starting diagonally from top left to bottom right until reaching the kth line, then go up to top right, and so on.So, if the input is ... Read More

Program to find length of longest alternating path of a binary tree in python

Arnab Chakraborty
Published on 26-Nov-2020 12:59:28
Suppose we have a binary tree, we have to find the longest path that alternates between left and right child and going down.So, if the input is likethen the output will be 5 as the alternating path is [2, 4, 5, 7, 8].To solve this, we will follow these steps:if ... Read More

Program to find length of longest word that can be formed from given letters in python

Arnab Chakraborty
Published on 26-Nov-2020 12:56:53
Suppose we have a list of words and a string called letters, we have to find the size of the longest word that can be made by rearranging the given letters. In the letters there may be asterisk character (*) it can match any character. And it is not necessary ... Read More

Program to count number of word concatenations are there in the list in python

Arnab Chakraborty
Published on 26-Nov-2020 12:55:21
Suppose we have a list of strings; we have to find the number of words that are concatenations of other words also in the list. We can reuse words when concatenating and concatenate any number of times.So, if the input is like words = ["hello", "world", "helloworld", "famous", "worldfamous", "programming"], ... Read More

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
1 2 3 4 5 6 7 ... 4286 Next
Advertisements