Category: algorithms
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all distinct …
Sort a linked list in O(n log n) time using constant space complexity. Example 1: Input: 4->2->->3 Output: 1->2->3->4 Example 2: Input: -1->5->3->4->0 Output: -1->0->3->4->5 The Merge sort performs …
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: Input: Output: 1->1->2->3->4->4->5->6 There are many algorithms that we can use …
The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for …
Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1. After doing …