From 98d689dd7b29e56ead7160a0fd03975797f05fd5 Mon Sep 17 00:00:00 2001 From: Aditya Nigam <75134530+Adi2209@users.noreply.github.com> Date: Sun, 21 May 2023 11:56:03 +0530 Subject: [PATCH 1/5] Create validSudoku.md Check if a sudoku is valid or not. Solved using the backtracking concept. --- Backtracking/validSudoku.md | 96 +++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 Backtracking/validSudoku.md diff --git a/Backtracking/validSudoku.md b/Backtracking/validSudoku.md new file mode 100644 index 0000000..4cf3181 --- /dev/null +++ b/Backtracking/validSudoku.md @@ -0,0 +1,96 @@ +
Determine if a 9 x 9
Sudoku board is valid. Only the filled cells need to be validated according to the following rules:
1-9
without repetition.1-9
without repetition.3 x 3
sub-boxes of the grid must contain the digits 1-9
without repetition.Note:
+ ++
Example 1:
+Input: board = +[["5","3",".",".","7",".",".",".","."] +,["6",".",".","1","9","5",".",".","."] +,[".","9","8",".",".",".",".","6","."] +,["8",".",".",".","6",".",".",".","3"] +,["4",".",".","8",".","3",".",".","1"] +,["7",".",".",".","2",".",".",".","6"] +,[".","6",".",".",".",".","2","8","."] +,[".",".",".","4","1","9",".",".","5"] +,[".",".",".",".","8",".",".","7","9"]] +Output: true ++ +
Example 2:
+ +Input: board = +[["8","3",".",".","7",".",".",".","."] +,["6",".",".","1","9","5",".",".","."] +,[".","9","8",".",".",".",".","6","."] +,["8",".",".",".","6",".",".",".","3"] +,["4",".",".","8",".","3",".",".","1"] +,["7",".",".",".","2",".",".",".","6"] +,[".","6",".",".",".",".","2","8","."] +,[".",".",".","4","1","9",".",".","5"] +,[".",".",".",".","8",".",".","7","9"]] +Output: false +Explanation: Same as Example 1, except with the 5 in the top left corner being modified to 8. Since there are two 8's in the top left 3x3 sub-box, it is invalid. ++ +
+
Constraints:
+ +board.length == 9
board[i].length == 9
board[i][j]
is a digit 1-9
or '.'
.Given n
non-negative integers representing an elevation map where the width of each bar is 1
, compute how much water it can trap after raining.
+
Example 1:
+Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] +Output: 6 +Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. ++ +
Example 2:
+ +Input: height = [4,2,0,3,2,5] +Output: 9 ++ +
+
Constraints:
+ +n == height.length
1 <= n <= 2 * 104
0 <= height[i] <= 105
Given an array of intervals
where intervals[i] = [starti, endi]
, merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.
+
Example 1:
+ +Input: intervals = [[1,3],[2,6],[8,10],[15,18]] +Output: [[1,6],[8,10],[15,18]] +Explanation: Since intervals [1,3] and [2,6] overlap, merge them into [1,6]. ++ +
Example 2:
+ +Input: intervals = [[1,4],[4,5]] +Output: [[1,5]] +Explanation: Intervals [1,4] and [4,5] are considered overlapping. ++ +
+
Constraints:
+ +1 <= intervals.length <= 104
intervals[i].length == 2
0 <= starti <= endi <= 104
Given a positive integer n
, generate an n x n
matrix
filled with elements from 1
to n2
in spiral order.
+
Example 1:
+Input: n = 3 +Output: [[1,2,3],[8,9,4],[7,6,5]] ++ +
Example 2:
+ +Input: n = 1 +Output: [[1]] ++ +
+
Constraints:
+ +1 <= n <= 20