Arnab Chakraborty has Published 4293 Articles

Minimum Number of Steps to Make Two Strings Anagram in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 12:37:48

273 Views

Suppose we have two equal-size strings s and t. In one step we can choose any character of t and replace it with another character. We have to find the minimum number of steps required to make t an anagram of s. Note: An Anagram of a string is a ... Read More

Insert Delete GetRandom O(1) in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 12:34:50

563 Views

Suppose we have a data structure that supports all following operations in average O(1) time.insert(val) − This will Insert an item val to the set if that is not already present.remove(val) − This will remove an item val from the set if it presents.getRandom − This will return a random ... Read More

Flatten Nested List Iterator in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 12:33:50

439 Views

Suppose we have a nested list of integers; we have to implement an iterator to flatten it. Each element is either an integer, or a list. The elements of that list may also be integers or other lists. So if the input is like [[1, 1], 2, [1, 1]], then ... Read More

House Robber III in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 12:32:55

438 Views

Suppose one thief has found himself a new place for his thievery again. There is only one entrance to this area, the entrance is called the "root." Besides the root, each house has one and only one parent house. After a tour, the smart thief felt that "all houses in ... Read More

Super Ugly Number in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 12:30:42

338 Views

We have to create one function to find the nth super ugly number. The super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. So if the n is 12 and primes are [2, 7, 13, 19], then the output ... Read More

Reduce Array Size to The Half in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 12:29:34

1K+ Views

Suppose we have an array arr. We can choose a set of integers and remove all the occurrences of these integers in the array. We have to find the minimum size of the set so that at least half of the integers of the array are removed. So for example, ... Read More

Course Schedule II in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 12:26:29

351 Views

Suppose there are a total of n courses, these are labeled from 0 to n-1. Some courses may have prerequisites, given the total number of courses and a list of prerequisite pairs, we have to find the ordering of courses that we should take to finish all courses. There may ... Read More

Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 12:26:21

737 Views

Suppose we have an array of integers arr and two integers k and threshold. We have to find the number of sub-arrays of size k and average greater than or equal to the threshold. So if the input is like: [2, 2, 2, 2, 5, 5, 5, 8] and k ... Read More

Course Schedule in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 12:25:39

1K+ Views

Suppose there are a total of numCourses courses we have to take, labeled from 0 to numCourses-1. Some courses may have prerequisites, for example to take course 0 we have to first take course 1, which is expressed using a pair: [0, 1]. Suppose there are total number of courses ... Read More

Word Ladder in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 12:23:44

867 Views

Suppose we have two words (beginWord and endWord), and we have dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that −Only one letter can be converted at a time.In each transformed word must exist in the word list. The beginWord is not a ... Read More

Advertisements