
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

149 Views
Suppose we have a list of list of strings called shows, also have a list of integers called durations, and another value k, here shows[i] and durations[i] represent a show and its duration watched by the ith man, we have to find the total duration watched of the k most watched shows.So, if the input is like shows = ["The BGT", "Jack jumper", "The BGT", "Jokers Company", "Music magic"] durations = [10, 8, 10, 18, 9] k = 2, then the output will be 38, as the top 2 most watched shows are "Jokers Company" and "The BGT" and total ... Read More

318 Views
Suppose we have a list of intervals and a value called point. Each interval interval[i] contains [si, ei] represents start time and end time of interval i (both inclusive). We have to find the number of intervals that are intersecting at given point.So, if the input is like intervals = [[2, 6],[4, 10],[5, 9],[11, 14]] point = 5, then the output will be 3, because at time 5, there are 3 intervals those are [3, 6], [4, 10], [5, 9]To solve this, we will follow these steps −count := 0for each start time i and end time j in intervals, doif point >= i and point = i and point

274 Views
Suppose we have a number n. Consider x = rand() mod n, where rand() function generates integers between 0 and 10^100 (both inclusive) uniformly at random. And$$Y = \sqrt{x+\sqrt{x+\sqrt{x+\sqrt{x+...}}}}$$We have to find the expected value of Y. The value of n will be in range 1 and 5*10^6.So, if the input is like n = 5, then the output will be 1.696To solve this, we will follow these steps −err := 2235.023971557617max_n := 5 * 10^6pref := a list initially contains a single 0for i in range 1 to 5 * 10^6, doinsert (last item of pref + (1 +(4*i ... Read More

1K+ Views
Suppose we have a list of elements; these elements are stored in a singly linked list. We also have a value pos and value val. We have to insert val before index pos of the linked list.So, if the input is like nums = [1, 5, 3, 6, 8] pos = 3 val = 7, then the output will be [1, 5, 3, 7, 6, 8]To solve this, we will follow these steps −new := create a linked list node with value same as valif pos is same as 0, thennext of new := list_headreturn newtemp := list_headwhile temp is ... Read More

159 Views
Suppose we have two strings s1 and s2. We have to find the size of longest string s3 which is special substring of both s1 and s2.We can say a string x is special substring of another string y if x can be generated by removing 0 or more characters from y.So, if the input is like s1 = 'pineapple' s2 = 'people', then the output will be 5 as the special substring is 'peple', of size 5.To solve this, we will follow these steps −prev := a new dictionary, where if some key is not present, return 0for i ... Read More

684 Views
Suppose we have a list of items called nums, we have to find the smallest index i such that the sum of the numbers which are present at the left of i is equal to the sum of numbers present at right of i. If we cannot find any such solution, return -1.So, if the input is like nums = [8, 2, 3, 6, 5, 2, 5, 9, 1, 2], then the output will be 4, because sum of elements that are left of index 4 is [8, 2, 3, 6] = 19, and sum of elements that are present ... Read More

4K+ Views
Suppose we have a list of elements called nums, we have to find the largest positive value that divides each of the integers.So, if the input is like nums = [15, 81, 78], then the output will be 3, as 3 is the largest integer that divides all 15, 81, and 78.To solve this, we will follow these steps −if size of nums is same as 1, thenreturn nums[0]div := gcd of nums[0] and nums[1])if size of nums is same as 2, thenreturn divfor i in range 1 to size of nums - 2, dodiv := gcd of div and ... Read More

684 Views
Suppose we have two inputs n and k. We have to check whether n can be represented as a sum of k number of prime values or not.So, if the input is like n = 30 k = 3, then the output will be True because 30 can be represented like 2 + 11 + 17.To solve this, we will follow these steps −if n < k*2, then return Falseif k > 2, then return Trueif k is same as 2, thenif n is even, then return Trueif (n-2) is prime, then return Truereturn Falseif n is prime, then return ... Read More

498 Views
Suppose we have a string s with lowercase letters. We have to find all in s where there must be another substring in s at a different location that is an anagram of that taken substrings. We have to find a list of substrings in in lexicographic order.So, if the input is like s = "abcba", then the output will be ['a', 'a', 'ab', 'abc', 'abcb', 'b', 'b', 'ba', 'bc', 'bcba', 'cb', 'cba'] for each of them we can find different anagrams present in the string itself.To solve this, we will follow these steps −res := a new listL := ... Read More

166 Views
Suppose we have a list of elements called nums where all items are unique, and they are sorted in ascending order, we have to find the minimum i such that nums[i] = i. If we cannot find any solution, then return -1. We have to solve this problem in O(log(n)) time.So, if the input is like nums = [-4, -1, 2, 3, 8], then the output will be 2, because both nums[2] = 2 and nums[3] = 3 but 2 is smaller.To solve this, we will follow these steps −ret := -1, lhs := 0, rhs := size of nums ... Read More