Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 287 of 377

Program to check heap is forming max heap or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 14-Oct-2021 1K+ Views

Suppose we have a list representing a heap tree. As we know heap is a complete binary tree. We have to check whether the elements are forming max heap or not. As we know for max heap every element is larger than both of its children.So, if the input is like nums = [8, 6, 4, 2, 0, 3], then the output will be True because, all elements are larger than their children.To solve this, we will follow these steps −n := size of numsfor i in range 0 to n - 1, dom := i * 2num := nums[i]if ...

Read More

Program to check all listed delivery operations are valid or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 14-Oct-2021 225 Views

Suppose we have a list of strings called orders. Each element in the orders list starts with either "P" or "D". The "P" indicates that is picked up, and "D" means "delivery". And these letters are followed by the order id number. For example, "P6" indicates pick up order 6. We have to check whether orders list is valid or not based on these rules −We cannot delivery an order before pickupEvery pickup must be deliveredAn order which is already been picked up and also delivered cannot be picked up or delivered againSo, if the input is like orders = ...

Read More

Program to find buildings from where sea can be visible in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 14-Oct-2021 435 Views

Suppose we have a list of heights of different buildings. A building with heights value heights[i] can see the ocean when every building on its right are shorter than that building. We have to find the building indices from where we can see the ocean, in ascending order.So, if the input is like heights = [8, 12, 12, 9, 10, 6], then the output will be [2, 4, 5] because we can see the ocean from building heights 12 at index 2, from building height 10 at index 10 and from last building at index 5.To solve this, we will ...

Read More

Program to find number of unique people from list of contact mail ids in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 14-Oct-2021 264 Views

Suppose we have a list of mail ids in a constants list. So for each row there may be more than one mail id of same person. The contact i is considered as duplicate when there's any j, where j < i such that contact j shares a common email with i. So we have to find the number of unique people in contacts.So, if the input is like contacts = [["alex@gmail.com", "alex@yahoo.com"], ["alex_25@yahoo.com", "alex@gmail.com"], ["bob15@gmail.com"] ], then the output will be 2, as the first and second contacts are sharing same mail ids, so they are same person, so ...

Read More

Program to check words can be found in matrix character board or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 14-Oct-2021 603 Views

Suppose we have a matrix character board. Where each cell is holding a character. We also have a string called target, we have to check whether the target can be found in the matrix by going left-to-right, or up-to-down unidirectional way, or not.So, if the input is likeantsspinlapsWord = “tip”then the output will be True, you can see the third column (top to bottom) is forming "tip".To solve this, we will follow these steps −for each i in board, doi := make word from characters present in iif word is present in i, thenreturn Truei := 0while i < row ...

Read More

Program to find minimum time required to complete tasks with k time gap between same type tasks in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 14-Oct-2021 427 Views

Suppose we have a list of integers called tasks where each item represents a different task type, we also have a non-negative integer say k. Each task takes one unit of time to complete and the tasks must be completed in correct order, but we must have k units of time between doing two same type tasks. At any time, either we can do a task or wait. We have to find the amount of time it takes to complete all the tasks.So, if the input is like tasks = [0, 1, 1, 2] k = 2, then the output ...

Read More

Program to find array by swapping consecutive index pairs in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 14-Oct-2021 535 Views

Suppose we have a list of numbers called nums, we have to return the list by swapping each consecutive even indexes with each other, and swapping each consecutive odd indexes with each other.So, if the input is like nums = [8, 5, 3, 4, 8, 9, 3, 6, 4, 7], then the output will be [3, 4, 8, 5, 3, 6, 8, 9, 4, 7]To solve this, we will follow these steps −for i in range 0 to size of nums - 2, increase by 4, doif i + 2 < size of nums, thenswap nums[i] and nums[i + 2]if ...

Read More

Program to check sum of two numbers is up to k from sorted List or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 14-Oct-2021 666 Views

Suppose we have a list of numbers called nums and the elements in nums are sorted in ascending order. We also have another value k, we have to check whether any two elements taken from the list add up to k or not. The numbers can also be negative or 0. We have to solve this problem in constant amount of space usage.So, if the input is like nums = [-8, -3, 2, 7, 9] k = 4, then the output will be True, because if we take 7 and -3, then the sum is 7 + (-3) = 4, ...

Read More

Program to find sum of two numbers which are less than the target in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 14-Oct-2021 779 Views

Suppose we have a list of numbers called nums and also have a target value, we have to find the sum of the largest pair of numbers in nums whose sum is at most (target-1).So, if the input is like nums = [8, 3, 4, 9, 2] target = 8, then the output will be 7, because the sum of the largest pair of numbers less than 8 is 4 + 3 = 7.To solve this, we will follow these steps −sort the list numsp1 := 0p2 := size of nums - 1m := -infwhile p1 < p2, doif nums[p1] ...

Read More

Program to create data structure to check pair sum is same as value in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 14-Oct-2021 156 Views

Suppose we want to make a data structure that has two methods −add(val) this adds the value val to the data structurefind(val) this checks whether there are two elements whose sum is val or notWe have to design this so that we can get the result on the fly. We will not search for numbers every time when a query comes.So, if the input is like create an object obj and add few numbers 6, 14, 3, 8, 11, 15, then check like obj.find(9), obj.find(11), obj.find(15), then the output will be True, True, False as 9 can be formed with ...

Read More
Showing 2861–2870 of 3,768 articles
« Prev 1 285 286 287 288 289 377 Next »
Advertisements