Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasyishak committed Nov 23, 2024
0 parents commit c1f18c4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[MESSAGES CONTROL]
disable=C0114,C0103,C0115,C0116
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ruff.lint.ignore": [
"C0114",
"E741"
]
}
51 changes: 51 additions & 0 deletions 1861.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# https://leetcode.com/problems/rotating-the-box
from typing import List


class Solution:
def rotate_the_box(self, box: List[List[str]]) -> List[List[str]]:

ROWS = len(box)
COLS = len(box[0])

for i in range(ROWS):
right = COLS - 1
left = right - 1
while right >= 0 and left >= 0:

right_val = box[i][right]
left_val = box[i][left]

# Ensure that the right spot is a valid spot we
# can swap a value with
if right_val != ".":
right -= 1
left -= 1
elif left_val == ".":
left -= 1
elif left_val == "#":
box[i][right] = "#"
box[i][left] = "."
right -= 1
left -= 1
elif left_val == "*":
left -= 1
right = left

transposed_box = [[None for _ in range(ROWS)] for _ in range(COLS)]
for i in range(ROWS):
for j in range(COLS):
transposed_box[j][i] = box[i][j]

rotated_box = [row[::-1] for row in transposed_box]

return rotated_box


if __name__ == "__main__":

test_case_1 = [["#", ".", ".", ".", "#"]]
test_case_2 = [["#", ".", "*", "."], ["#", "#", "*", "."]]

cls = Solution()
cls.rotate_the_box(box=test_case_2)

0 comments on commit c1f18c4

Please sign in to comment.