[LeetCode 2345 ] Finding the number of visible mountains | One pass Argo

  Рет қаралды 592

Lulu Code

Lulu Code

Күн бұрын

Пікірлер: 6
@shivamshrey47
@shivamshrey47 5 ай бұрын
python3 class Solution: def visibleMountains(self, peaks: List[List[int]]) -> int: # sort peaks in ascending order of (x - y) x-intercept # and also in descending order of (x + y) x-intercept peaks.sort(key=lambda x: ((x[0] - x[1]), -(x[0] + x[1]))) count = 0 max_end = float('-inf') for i, (x, y) in enumerate(peaks): if x + y > max_end: max_end = x + y if i < len(peaks) - 1 and peaks[i] == peaks[i + 1]: continue count += 1 return count
@leelashreerajendran8726
@leelashreerajendran8726 10 ай бұрын
Brute force solution : #assume the widest base and tallest mountain max_x = input[0][0] max_y = input[0][1] #calculate the widest base and tallest mountain for i in input: left_base = i[0]-i[1] right_base = i[0]+i[1] max_x = max(max_x, left_base) max_y = max(max_y, i[1]) #generate a 2D map of the scenery scenery = [[0 for i in range(max_y+1)] for j in range(-1*max_x, max_x + 1)] #populate the overlapping mountains for i in input: scenery[i[0]][i[1]] += 1 temp_y = i[1] - 1 counter = 1 while (temp_y > 0): for j in range(counter): scenery[i[0]-j][temp_y] += 1 scenery[i[0]+j][temp_y] += 1 counter += 1 temp_y -= 1 #Find the peaks which are not overlapped visible_mountain = 0 for i in input: if scenery[i[0]][i[1]] == 1: visible_mountain += 1 print(visible_mountain)
@berserk.4121
@berserk.4121 Жыл бұрын
Continue making videos 👍
@CodeCode-pz6oo
@CodeCode-pz6oo Жыл бұрын
Thanks!
@noppa2576
@noppa2576 Жыл бұрын
Thanks
@CodeCode-pz6oo
@CodeCode-pz6oo Жыл бұрын
Thanks!
Weekly Contest 312  |  2421. Number of Good Paths
24:01
codingMohan
Рет қаралды 7 М.
Alat yang Membersihkan Kaki dalam Hitungan Detik 🦶🫧
00:24
Poly Holy Yow Indonesia
Рет қаралды 11 МЛН
Google Coding Interview With A High School Student
57:24
Clément Mihailescu
Рет қаралды 4,1 МЛН
Seneca - IPC144: Height Converter
34:31
cathyatseneca
Рет қаралды 94
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
Google Coding Interview With A Competitive Programmer
54:17
Clément Mihailescu
Рет қаралды 2,5 МЛН
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
LeetCode 2104. Sum of Subarray Ranges
24:37
Kacy Codes
Рет қаралды 10 М.
Arenas, strings and Scuffed Templates in C
12:28
VoxelRifts
Рет қаралды 85 М.