Suppose we have a matrix of order m x n called accounts where accounts[i][j] is the amount of money of ith customer present in jth bank. We have to find the wealth that the richest customer has. A customer is richest when he/she has maximum amount considering all banks.So, if the input is like102015305201051215123then the output will be 55 as the money of second person is 30+5+20 = 55, which is maximum.To solve this, we will follow these steps −max_balue := 0ind_value := 0for i in range 0 to row count of accounts - 1, doind_value := sum of all ... Read More
Suppose we have a sequence of characters called s, we say a string w is k-repeating string if w is concatenated k times is a substring of sequence. The w's maximum k-repeating value will be the highest value k where w is k-repeating in sequence. And if w is not a substring of the given sequence, w's maximum k-repeating value is 0. So if we have s and w we have to find the maximum k-repeating value of w in sequence.So, if the input is like s = "papaya" w = "pa", then the output will be 2 as w ... Read More
Suppose we have two string type arrays word1 and word2, we have to check whether the two arrays represent the same string or not. We can say a string can be represented by an array if the elements in that array are concatenated in order forms the string.So, if the input is like word1 = ["ko", "lka", "ta"] word2 = ["k", "olk", "at", "a"], then the output will be True as both are forming "kolkata".To solve this, we will follow these steps −s1:= blank string, s2:= blank stringfor each string i in word1, dos1 := s1 concatenate ifor each string ... Read More
Suppose there is a bomb that you are going to defuse, and your time is running out! You have a a circular array code of length of n and have a key k. Now to decrypt the code, you must replace every number. All the numbers are replaced simultaneously. There are few rules −If k > 0 then replace ith number with the sum of next k numbers.If k < 0 then replace ith number with the sum of previous k numbers.If k = 0 then replace ith number with 0.Here the code is circular, so the next element of ... Read More
We can retrieve the file extension using multiple ways. First, using the [System.IO.Path] class.PS C:\> [System.IO.Path]::GetExtension("C:\temp\25Aug2020.txt") .txt PS C:\> [System.IO.Path]::GetExtension("C:\temp\azcopy.zip") .zipThis is the easiest way to get the file extension. Otherways, Using programmatically, PS C:\> ((Split-Path "C:\Temp\azcopy.zip" -Leaf).Split('.'))[1] zip PS C:\> ((Split-Path "C:\Temp\25Aug2020.txt" -Leaf).Split('.'))[1] txtUsing Get-ChildItem, PS C:\> (Get-ChildItem C:\Temp\azcopy.zip).Extension .zip PS C:\> (Get-ChildItem C:\Temp\25Aug2020.txt).Extension .txtUsing Get-Item, PS C:\> (Get-Item C:\Temp\azcopy.zip).Extension .zipRead More
Suppose we have a number n. We have to generate an array A of length n + 1 in the following way −A[0] = 0A[1] = 1A[2 * i] = A[i] if 2
Suppose we have an array nums where all elements are unique and have another array with different smaller arrays called pieces. We have to check whether we can get the main array nums by concatenating the arrays in pieces in any order or not. But we are not allowed to reorder the elements present in each array pieces[i].So, if the input is like nums = [5, 1, 12, 36, 2, 47, 6] pieces = [[2, 47, 6], [12, 36], [1], [5]], then the output will be True because we can concatenate them in this order [[5], [1], [12, 36], [2, ... Read More
Suppose we have an array with some elements where elements may appear multiple times. We have to sort the array such that elements are sorted according to their increase of frequency. So which element appears less number of time will come first and so on.So, if the input is like nums = [1, 5, 3, 1, 3, 1, 2, 5], then the output will be [2, 5, 5, 3, 3, 1, 1, 1]To solve this, we will follow these steps −mp := a new mapfor each distinct element i from nums, dox:= number of i present in numsif x is ... Read More
Suppose we have a string s, we have to find the length of the longest substring between two equal letters or elements, excluding the two characters. If we cannot find such substring, then return -1.So, if the input is like s = "level", then the output will be 3 as optimal substrings can be either "lev" or "vel".To solve this, we will follow these steps −memo := a new mapfor i in range 0 to size of s - 1, doif s[i] is in memo, theninsert i at the end of memo[s[i]]otherwise, memo[s[i]] := a list with only one element ... Read More
Suppose we have array called nums, we have to find the mean of the remaining values after removing the smallest 5% and the largest 5% of the elements.So, if the input is like nums = [2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8], then the output will be 4.0 because after removing smallest and largest values, all are same, then the median isTo solve this, we will follow these steps −sort the list numsn := size of numsper := quotient of (n*5/100)l2 := subarray of nums from index ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP