Skip to content

Commit d5c2539

Browse files
committed
adding remove element
1 parent ae5c7f9 commit d5c2539

5 files changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from typing import List
2+
3+
class Solution:
4+
5+
def algo_1(self, names: List[str]):
6+
7+
dic_solution = dict()
8+
9+
for n in names:
10+
if n in dic_solution:
11+
dic_solution[n] += 1
12+
else:
13+
dic_solution[n] = 1
14+
15+
names.sort(key=lambda x: dic_solution[x], reverse=True)
16+
17+
18+
return names[0], dic_solution[names[0]]
19+
20+
21+
22+
solution = Solution()
23+
24+
print(solution.algo_1(names=['paola','mariana','mariana']))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from typing import List
2+
3+
class Solution:
4+
5+
def algo_1(self, names: List[str]):
6+
7+
8+
names.sort(key=lambda x: len(x), reverse=True)
9+
10+
11+
return names[0]
12+
13+
14+
15+
solution = Solution()
16+
17+
print(solution.algo_1(names=['paola','mariana','stephanos']))

src/my_project/interviews/interview_amazon/round_1/algo_3.py

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import List, Union, Collection, Mapping, Optional
2+
from abc import ABC
3+
4+
class Solution:
5+
6+
def removeElement(self, nums: List[int], val: int) -> int:
7+
8+
while val in nums:
9+
10+
nums.remove(val)
11+
12+
return len(nums)
13+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import unittest
2+
from src.my_project.interviews.top_150_questions_round_17\
3+
.remove_element import Solution
4+
5+
class RemoveElementTestCase(unittest.TestCase):
6+
7+
def test_remove_element(self):
8+
solution = Solution()
9+
output = solution.removeElement(nums=[3,2,2,3], val=3)
10+
target = 2
11+
self.assertEqual(output, target)

0 commit comments

Comments
 (0)