Skip to content

Instantly share code, notes, and snippets.

@tonoy30
Created December 21, 2022 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonoy30/fdeb11fe0f4ea04d4a957fe5b384c32c to your computer and use it in GitHub Desktop.
Save tonoy30/fdeb11fe0f4ea04d4a957fe5b384c32c to your computer and use it in GitHub Desktop.
airwrk codding test (21/12/2022)
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)
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)
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