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
Server Side Programming Articles - Page 1775 of 2650
915 Views
Suppose we have one unsorted integer array; we have to find the smallest missing positive number. So if the array is like [4, -3, 1, -1], then the result will be 2.To solve this, we will follow these steps −set i := 0 and update array nums by adding one 0 before all numbersfor i in range 0 to length of numswhile nums[i] >= 0 and nums[i] < length of nums and nums[nums[i]] is not nums[i] −nums[nums[i]] := nums[i]nums[i] := nums[nums[i]]num := 1for i in range 1 to length of numsif num = nums[i], then increase num by 1return numExampleLet ... Read More
17K+ Views
Suppose we have a Sudoku grid and we have to solve this famous number maze problem, Sudoku. We know that Sudoku is a 9 x 9 number grid, and the whole grid are also divided into 3 x 3 boxes There are some rules to solve the Sudoku.We have to use digits 1 to 9 for solving this problem.One digit cannot be repeated in one row, one column or in one 3 x 3 box.Using backtracking algorithm, we will try to solve Sudoku problem. When some cell is filled with a digit, it checks whether it is valid or not. ... Read More
1K+ Views
Suppose we have a string, with opening and closing parentheses. We have to find the longest length of the valid (well-formed) parentheses. So if the input is like “))(())())”, then the result will be 6, as the valid string is “(())()”.To solve this, we will follow these steps −Make a stack, and insert -1., set ans := 0for i in range 0 to length of stack – 1if s[i] is opening parentheses, then insert i into stackotherwiseif stack is not empty and top of stack is not -1 and s[stack top] is opening parentheses, thentop element from stackans := max ... Read More
198 Views
Suppose we have a string, s, and we also have a list of words, words present in the array are all of the same length. We have to find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters.So if the input is like “barfoothefoobarman” and words are [“foo”, “bar”], then the output will be [0, 9]. This is because the substring starting at index 0 and 9 are “barfoo” and “foobar”.To solve this, we will follow these steps −Define a method called ok(), this will take ... Read More
277 Views
Suppose we have a linked list, we have to reverse the nodes of the linked list k at a time and return its modified list. Here k is a positive integer and is less than or equal to the length of the linked list. So if the number of nodes is not a multiple of k then left-out nodes, in the end, should remain as it is.So if the linked list is like [1, 2, 3, 4, 5, 6, 7] and k is 3, then the result will be [3, 2, 1, 6, 5, 4, 7].To solve this, we will ... Read More
968 Views
Suppose we have some lists, these are sorted. We have to merge these lists into one list. To solve this, we will use the heap data structure. So if the lists are [1, 4, 5], [1, 3, 4], [2, 6], then the final list will be [1, 1, 2, 3, 4, 4, 5, 6].To solve this, we will follow these steps −make one heapfor each linked list l in lists −if is in not 0, then insert I into a heapres := null and res_next := nullDo one infinite loop −temp := min of heapif heap has no element, then ... Read More
533 Views
Suppose we have an input string s and another input string p. Here s is the main string and p is the pattern. We have to define one method, that can match patterns in the string. So we have to implement this for a regular expression, that supports ‘.’ And ‘*’.Dot ‘.’ Matches any single characterStar ‘*’ Matches zero or more of the preceding element.So for example, if the input is like s = “aa” and p = “a.”, then it will be true, for the same input string, if the patter is “.*”, then it will be true.To solve ... Read More
472 Views
Suppose we have two arrays; these arrays are sorted. So we have to find the median of these two arrays. So if the arrays are like [1,5,8] and [2,3,6,9], then the answer will be 5.To solve this, we will follow these steps −Define a function findMedianSortedArrays, this will take nums1 and nums2 arraysif size of nums1 > size of nums2, then,Call the function return findMedianSortedArrays(nums2, nums1)x := size of nums1, y := size of nums2low := 0, high := xtotalLength := x + ywhile low
355 Views
As part of data analysis using Python we may be required to to convert the data container from set to list. In this article we'll see e how to solve this requirement.With listThis is a straightforward approach in which we directly apply the list function on the given set. The elements get converted into elements of a list.Example Live DemosetA = {'Mon', 'day', '7pm'} # Given Set print("Given set : ", setA) res = (list(setA) ) # Result print("Final list: ", res)OutputRunning the above code gives us the following result −Given set : ['7pm', 'Mon', 'day'] Final list: ['7pm', 'Mon', 'day']With ... Read More
11K+ Views
As part of data manipulation in Python we may sometimes need to convert a given number into a list which contains the digits from that number. In this article we'll see the approaches to achieve this.With list comprehensionIn the below approach we apply the str function to the given number and then convert into integer through identity function. Finally we wrap the result into a list.Example Live DemonumA = 1342 # Given number print("Given number : ", numA) res = [int(x) for x in str(numA)] # Result print("List of number: ", res)OutputRunning the above code gives us the following result −Given ... Read More