Arnab Chakraborty has Published 4293 Articles

Nth Magical Number in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-Jun-2020 08:39:41

238 Views

A number is said to be a magical number, if that number is divisible by A or B. We have to find the Nth magical number. As the answer may very large, we will return it modulo 10^9 + 7.So, if the input is like N = 4, A = ... Read More

Minimum Number of Refueling Stops in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-Jun-2020 08:36:52

557 Views

Suppose there is a car, that travels from a starting position to a destination which is t miles east of the starting position.Now along the way, there are many gas stations. So each station[i] represents a gas station that is station[i][0] miles east of the starting position, and that station ... Read More

Shortest Subarray with Sum at Least K in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-Jun-2020 08:33:51

443 Views

Suppose we have an array A. We have to find the length of the shortest, non-empty, contiguous subarray of A whose sum is at least K. If there is no such subarray, then return -1.So, if the input is like [5, 3, -2, 2, 1] and k = 6, then ... Read More

Minimum Cost to Hire K Workers in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-Jun-2020 08:29:07

558 Views

Suppose there are N workers. Each worker has the quality parameter. The i-th worker has a quality[i] and a minimum wage expectation wage[i]. Now we want to hire K workers to form a paid group. When we are hiring a group of K workers, we must pay them according to ... Read More

K-Similar Strings in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-Jun-2020 08:24:52

300 Views

Suppose we have two strings A and B. These two strings are K-similar (where K is one nonnegative integer) if we can swap the positions of two letters in A exactly K times so that the resulting string is B. So, we have two anagrams A and B, we have ... Read More

Shortest Path Visiting All Nodes in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-Jun-2020 08:21:38

1K+ Views

Suppose we have one undirected, connected graph with N nodes these nodes are labeled as 0, 1, 2, ..., N-1. graph length will be N, and j is not same as i is in the list graph[i] exactly once, if and only if nodes i and j are connected. We ... Read More

Similar String Groups in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-Jun-2020 08:17:43

283 Views

Suppose we have two strings X and Y, these are similar if we can swap two letters of X, so that it equals Y. Also two the strings X and Y are similar if they are equal. As an example, consider, two strings are like "tars" and "rats" are similar, ... Read More

Sum of Distances in Tree in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-Jun-2020 08:13:41

712 Views

Suppose we have one undirected, connected tree where N nodes are present. These are labelled as 0...N-1 and N-1 edges are given. The ith edge connects nodes edges[i][0] and edges[i][1] together. We have to find a list where ans[i] is the sum of the distances between node i and all ... Read More

Consecutive Numbers Sum in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-Jun-2020 08:07:41

1K+ Views

Suppose we have a positive integer N, we have to find how many different ways can we write it as a sum of consecutive positive integers?So, if the input is like 10, then the output will be 3, this is because we can represent 10 as 5 + 5 and ... Read More

Minimum Insertion Steps to Make a String Palindrome in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-Jun-2020 11:36:26

315 Views

Suppose we have a string s, we have to make this string palindrome. in each step we can insert any character at any position, we have to find minimum number of characters that require to make this palindrome. If the string is like “mad”, then the answer will be 2 ... Read More

Advertisements