Skip to content

Instantly share code, notes, and snippets.

MERGE CONTACTS

Sebuah perusahaan mobile application ingin membuat sebuah API yang menyimpan kontak info dari user. Namun user memiliki beberapa data source untuk kontak, ada yang dari GMail, Yahoo, dan lainnya. Permasalahannya dari beberapa data source tersebut ternyata ada banyak kontak yang sama. Nah karena kontak API ini mesti memudahkan user untuk mencari kontak yang diinginkan, maka kontak-kontak dari beberapa sumber tersebut mesti di-merge.

Contoh struktur dari data sebuah kontak adalah sbb:

Contact {
    id: string
 fullname: string
@mamaz
mamaz / fsm.md
Last active December 9, 2019 03:42
Finite State Machine

Finite State Machine

Desain sebuah Finite State Machine (FSM) sebuah lift.

Beberapa state dalam lift tersebut adalah:

  • Pintu membuka
  • Pintu menutup
  • Pintu tertutup
  • Pintu terbuka

Swap Linked List

Diberikan LinkedList dengan dengan struktur data setiap Node:

{
  value: int
  next: * Node
}
@mamaz
mamaz / checksum.py
Last active March 30, 2020 20:03
sum from List, checksum(0, [2,4,8], 6) -> True, checksum(0, [2,4,8], 15) -> False
from typing import List
def checksum(acc: int, lst: List[int], exist_total: int)-> bool:
sorted_nums = sorted(lst)
return checksum_rec(sorted_nums, exist_total, exist_total)
def checksum_rec(nums: List, exist_total: int, orig_total: int)->int:
if len(nums) == 0 and exist_total > 0:
return False
else:
user, _ := GetUserByID(context.Background, ID)
// do the rest of the code
@mamaz
mamaz / asynchronous.md
Last active January 11, 2024 02:59
Soal Asynchronous Go

Deskripsi

Buatlah sebuah program commad-line program Web Crawler dengan Go

Input berupa list of URL yang ada dalam sebuah file urls.txt, yang kemudian akan di crawl dan disimpan ke dalam beberapa file html.

File-file html tersebut akan disimpan di sebuah folder result di direktori tempat crawl command di execute.

Contoh

Command