Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import List, Union, Collection, Mapping, Optional
from abc import ABC, abstractmethod

class Solution:
def findMinArrowShots(self, points: List[List[int]]) -> int:
if not points:
return 0

# Sort balloons by end coordinate
points.sort(key=lambda x: x[1])

arrows = 1
current_arrow_pos = points[0][1]

for i in range(1, len(points)):
# If current balloon starts after the last arrow position,
# we need a new arrow
if points[i][0] > current_arrow_pos:
arrows += 1
current_arrow_pos = points[i][1]

return arrows
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function removeElement(nums: number[], val: number): number {
while (nums.includes(val)){
const index = nums.indexOf(val);
nums.splice(index, 1);
}

return nums.length;

};

console.log(removeElement([3,2,2,3], 3))
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import unittest
from src.my_project.interviews.top_150_questions_round_22\
.ex_49_min_number_arrows_burst_ballons import Solution

class ArrowsBurstBallonsTestCase(unittest.TestCase):

def test_first_pattern(self):
solution = Solution()
output = solution.findMinArrowShots(points = [[10,16],[2,8],[1,6],[7,12]])
target = 2
self.assertEqual(output, target)

def test_second_pattern(self):
solution = Solution()
output = solution.findMinArrowShots(points = [[1,2],[3,4],[5,6],[7,8]])
target = 4
self.assertEqual(output, target)

def test_third_pattern(self):
solution = Solution()
output = solution.findMinArrowShots(points = [[1,2],[2,3],[3,4],[4,5]])
target = 2
self.assertEqual(output, target)