Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 69 of 377

Flip Game II in C++

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

Suppose there are two players who are playing the flip game. Here we have a string that contains only these two characters: + and -, player1 and player2 take turns to flip two consecutive "++" into "--". The game ends when one player can no longer make a move and therefore the other one will be the winner. We have to define a function to check whether the starting player can guarantee a win.So, if the input is like s = "++++", then the output will be true, as the starting player can guarantee a win by flipping the middle ...

Read More

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

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

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 will be 03:30, as the nearest time 03:30 that repeats the given digits.To solve this, we will follow these steps:use := a list with two digit hour and two digit mins valuespossible := a new setDefine a function backtrack() . This will take pathif size of path is same as ...

Read More

Binary Tree Longest Consecutive Sequence in C++

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

Suppose we have a binary tree; we have to check whether we can find the length of the longest consecutive sequence path. If the path refers to any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The longest consecutive path need to follow parent to child but not reverse.So, if the input is like, then the output will be 3, as the Longest consecutive sequence path is 3-4-5, so return 3.To solve this, we will follow these steps −Define a function solveUtil(), this will take node, prev, len initialize it with ...

Read More

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

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

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"], then the output will be 2, as "helloworld" is concatenation of "hello" and "world". "worldfamous" is concatenation of "world" and "famous".To solve this, we will follow these steps:trie := a new mapfor each word in words, dolayer := triefor each w in word, doif w is not in layer, thenlayer[w] ...

Read More

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

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

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 to use all the letters.So, if the input is like words = ["prince", "rice", "price", "limit", "hello"] letters = "*r**ce*", then the output will be 6, as the longest word we can make is "prince" the length is 6.To solve this, we will follow these steps:has := a map containing ...

Read More

Program to reverse the directed graph in Python

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

Suppose we have a directed graph, we have to find its reverse so if an edge goes from u to v, it now goes from v to u. Here input will be an adjacency list, and if there are n nodes, the nodes will be (0, 1, ..., n-1).So, if the input is likethen the output will beTo solve this, we will follow these steps −ans := a list of n different lists, where n is number of verticesfor each index i, and adjacent list l in graph, dofor each x in l, doinsert i at the end of ans[x]return ...

Read More

Binary Tree Vertical Order Traversal in C++

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

Suppose there is a binary tree, we have to find the vertical order traversal of its nodes' values. If two nodes are in the same row and column, the order should be from left to right.So, if the input is like, then the output will be [[9], [3, 15], [20], [7]]To solve this, we will follow these steps −Define one map mDefine a function solve(), this will take node, x initialize it with 0, if node is null, then −returnsolve(left of node, x - 1)solve(right of node, x + 1)insert value of node at the end of m[x]From the main ...

Read More

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

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

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 root is null, thenreturn 0Define a function dfs() . This will take node, count, flagif node is not null, thenif flag is same as True, thena := dfs(left of node, count + 1, False)b := dfs(right of node, 1, True)otherwise when flag is same as False, thena := dfs(right of ...

Read More

Generalized Abbreviation in C++

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

Suppose there is a word. We have to define a function that can generate the generalized abbreviations of a word.So, if the input is like "word", then the output will be ["word", "1ord", "w1rd", "wo1d", "wor1", "2rd", "w2d", "wo2", "1o1d", "1or1", "w1r1", "1o2", "2r1", "3d", "w3", "4"]To solve this, we will follow these steps −Define an array retDefine a function solve(), this will take s, idx, if idx >= size of s, then −insert s at the end of retreturny := substring of s from index 0 to idx - 1i := size of ynum := blank stringwhile (i >= ...

Read More

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

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

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 like s = "ilovepythonprogramming" k = 5, then the output will beTo solve this, we will follow these steps:line := a new mapcnt := 0delta := 1for each index i and character c in s, doinsert (c, i) at the end of line[cnt]cnt := cnt + deltaif cnt is same ...

Read More
Showing 681–690 of 3,768 articles
« Prev 1 67 68 69 70 71 377 Next »
Advertisements