
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

279 Views
Suppose we have a linked list. We have to take the first half of the linked list and fold over the second half then merge the intersecting nodes by taking their sum. Finally, we have to return the resulting head of the linked list.So, if the input is like [5, 8, 1, 2, 4, 7, 5], then the output will be [2, 5, 15, 10, ]To solve this, we will follow these steps −temp := 0ptr := nodewhile ptr is not null, dotemp := temp + 1ptr := next of ptrt := quotient of temp / 2m := nodestk := ... Read More

400 Views
Suppose we have a singly linked list, and another value called target, we have to remove the last occurrence of target in the given list.So, if the input is like [5, 4, 2, 6, 5, 2, 3, 2, 4, 5, 4, 7], target = 5, then the output will be [5, 4, 2, 6, 5, 2, 3, 2, 4, 4, 7, ]To solve this, we will follow these steps −head := nodek := null, prev := nullfound := Falsewhile node is not null, doif value of node is same as target, thenfound := Trueprev := kk := nodenode := next ... Read More

3K+ Views
Suppose we have a list coordinates in a Cartesian plane, we have to check whether the coordinates form a straight line segment or not.So, if the input is like coordinates = [(5, 5), (8, 8), (9, 9)], then the output will be True, as these points are forming a line segment with a slope 1.To solve this, we will follow these steps −(x0, y0) := coordinates[0](x1, y1) := coordinates[1]for i in range 2 to size of coordinates list - 1, do(x, y) := coordinates[i]if (x0 - x1) * (y1 - y) is not same as (x1 - x) * (y0 ... Read More

353 Views
Suppose we have a string s that is a palindrome. We have to change one character such that s is no longer a palindrome and it is lexicographically smallest.So, if the input is like s = "level", then the output will be "aevel", as we can change the first "l" to "a" to get the lexicographically smallest string that is not palindrome.To solve this, we will follow these steps −for i in range 0 to integer part of(size of s / 2), doif s[i] is not same as "a", thens := a new list from all characters in ss[i] := ... Read More

132 Views
Suppose we have two strings s and t of the same size, we have to check whether there is some permutation of s, say s1, and permutation of t, say t1, such that: s1[i] ≤ t1[i] for all 0 ≤ i < n or t1[i] ≤ s1[i] for all 0 ≤ i < n.So, if the input is like s = "vyx" t = "wzx", then the output will be True, as we can have s1 = "vxy" and t1 = "wxz".To solve this, we will follow these steps −if s and t are empty, thenreturn Trues := sort the ... Read More

527 Views
Suppose we have a list of tower heights, and a positive value k. We want to select k towers and make them all the same height by adding more bricks, but using as few bricks as possible. We have to find the minimum number of bricks are needed to pick k towers and make them the same height.So, if the input is like heights = [4, 7, 31, 14, 40] k = 3, then the output will be 17, as we can select 5, 8, and 15 which requires 17 bricks to make the same height.To solve this, we will ... Read More

315 Views
Suppose we have a list of numbers called nums that is representing a circular list. We have to find the largest sum of non-adjacent numbers.So, if the input is like nums = [10, 3, 4, 8], then the output will be 14, as we can take 10 and 4. We cannot take 10 and 8 as they are adjacent.To solve this, we will follow these steps −n := size of numsnums1 := nums[from index 0 to n - 2]nums2 := nums[from index 1 to end]Define a function f() . This will take iif i >= size of nums1 , thenreturn ... Read More

271 Views
Suppose we have a list of numbers called nums, and another value k, which represents a large list of nums concatenated k times. We have to find the sum of the contiguous sublist with the largest sum.So, if the input is like nums = [1, 3, 4, -5], k = 1, then the output will be 11, as we can take the sublist like [2, 4, 5]To solve this, we will follow these steps −s := ans := lo := 0for all value in range 0 to minimum of k and 2, dofor each x in nums, dos := s ... Read More

387 Views
Suppose we have a binary matrix. Here 1 represents land and 0 represents water, And an island is a group of 1s that are neighboring whose perimeter is surrounded by water. We can assume that the edges of the matrix are surrounded by water. We have to find the area of the largest island in matrix.So, if the input is like001111100000000111100001100000000110000010then the output will be 6.To solve this, we will follow these steps −Define a function dfs() . This will take matrix, r, ctotal := total + 1matrix[r, c] := 0if r - 1 >= 0 and matrix[r - 1, ... Read More

160 Views
Suppose we have two list of numbers called A and B, and their lengths are same. We have to find the maximum value for all 0 ≤ i < j < n: |a[i] - a[j]| + |b[i] - b[j]| + |i - j|So, if the input is like A = [2, 4, 10, 6] B = [3, 4, 7, 5], then the output will be 14, as when i = 0 and j = 2 and we get |2 - 10| + |3 - 7| + |1 - 3|.To solve this, we will follow these steps −ans := 0n := ... Read More