Arnab Chakraborty has Published 4293 Articles

Check If a Number Is Majority Element in a Sorted Array in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 28-Apr-2020 08:54:42

320 Views

Suppose we have an array called, nums and that is sorted in non-decreasing order, and a number target. We have to find if the target is a majority element. In an array a majority element is an element that appears more than N/2 times in an array of length N. ... Read More

Largest Unique Number in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 28-Apr-2020 08:46:16

566 Views

Suppose we have a list of numbers, we have to return the number whose occurrence is 1, if no such element is present, then return -1. So if the list is like [5, 2, 3, 6, 5, 2, 9, 6, 3], then the output will be 9.To solve this, we ... Read More

Remove Vowels from a String in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 28-Apr-2020 08:41:54

2K+ Views

Suppose we have a string, we have to remove all vowels from that string. So if the string is like “iloveprogramming”, then after removing vowels, the result will be − "lvprgrmmng"To solve this, we will follow these steps −create one array vowel, that is holding [a, e, i, o, u]for ... Read More

Valid Parentheses in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 28-Apr-2020 08:40:23

6K+ Views

Suppose we have an expression. The expression has some parentheses; we have to check the parentheses are balanced or not. The order of the parentheses are (), {} and []. Suppose there are two strings. “()[(){()}]” this is valid, but “{[}]” is invalid.The task is simple; we will use the ... Read More

Number of days in a month in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 28-Apr-2020 08:35:20

7K+ Views

Suppose we have one year Y and a month M, we have to return the number of days of that month for the given year. So if the Y = 1992 and M = 7, then the result will be 31, if the year is 2020, and M = 2, ... Read More

Two Sum Less Than K in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 28-Apr-2020 08:31:32

856 Views

Suppose we have an array A of integers and another integer K is given. We have to find the maximum S such that there exists i < j with A[i] + A[j] = S and S < K. If there is no i, j exists satisfying this equation, then return ... Read More

Index Pairs of a String in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 28-Apr-2020 08:27:27

929 Views

Suppose we have a text string and words (a list of strings), we have to find all index pairs [i, j] such that the substring text[i]...text[j] is in the list of words. So if the string is like “ababa” and words array is like [“aba”, “ab”], then the output will ... Read More

Fixed Point in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 28-Apr-2020 08:24:35

1K+ Views

Suppose we have an array A of unique integers sorted in ascending order, we have to return the smallest index i that satisfies A[i] == i. Return -1 if no such i exists. So if the array is like [-10, -5, 0, 3, 7], then the output will be 3, ... Read More

Two Sum in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 28-Apr-2020 08:04:05

19K+ Views

Suppose we have an array of integers. We have to return the indices of two integers, such that if we add them up, we will reach to a specific target that is also given. Here we will take one assumption, that is always there will be one unique solution in ... Read More

Triangle in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 28-Apr-2020 07:14:50

364 Views

Suppose we have a triangle. We have to find the minimum path sum from top to the bottom. In each step, we can move to adjacent numbers on the row below.For example, if the following triangle is like[       [2],      [3, 4],     [6, 5, ... Read More

Advertisements