Created
December 21, 2022 16:25
-
-
Save tonoy30/fdeb11fe0f4ea04d4a957fe5b384c32c to your computer and use it in GitHub Desktop.
airwrk codding test (21/12/2022)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List | |
def good_pair(nums: List[int]) -> int: | |
good_pair_count = 0 | |
for i in range(len(nums)): | |
for j in range(i+1, len(nums)): | |
if nums[i] == nums[j] and i < j: | |
good_pair_count += 1 | |
return good_pair_count | |
nums = [1, 2, 3] | |
ans = good_pair(nums) | |
print(ans) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
from typing import List | |
def find_single(nums: List[int]) -> int: | |
freq = Counter(nums) | |
for key in freq: | |
if freq[key] == 1: | |
return key | |
return None | |
nums = [4, 1, 2, 1, 2] | |
ans = find_single(nums) | |
print(ans) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def truncate_sentence_to_k(s: str, k: int) -> str: | |
splitted_str = s.split(" ") | |
return " ".join(splitted_str[:k]) | |
s, k = "What is the solution to this problem", 4 | |
ans = truncate_sentence_to_k(s, k) | |
print(ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment