{"id":27253430,"url":"https://github.com/marselester/interview","last_synced_at":"2025-08-01T07:12:23.483Z","repository":{"id":143042060,"uuid":"314032607","full_name":"marselester/interview","owner":"marselester","description":"Interview notes.","archived":false,"fork":false,"pushed_at":"2022-12-23T22:07:27.000Z","size":327,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T01:36:30.283Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marselester.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-18T19:10:37.000Z","updated_at":"2023-11-28T12:52:28.000Z","dependencies_parsed_at":"2023-03-25T14:18:10.690Z","dependency_job_id":null,"html_url":"https://github.com/marselester/interview","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/marselester/interview","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marselester%2Finterview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marselester%2Finterview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marselester%2Finterview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marselester%2Finterview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marselester","download_url":"https://codeload.github.com/marselester/interview/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marselester%2Finterview/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268185170,"owners_count":24209381,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-11T01:27:31.145Z","updated_at":"2025-08-01T07:12:23.435Z","avatar_url":"https://github.com/marselester.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Interview\n\nInterview notes and Go implementation of a few problems from Elements of Programming Interviews.\n\nTable of content:\n\n- [Site reliability engineering](notes/sre.md)\n- [Systems performance](notes/sysperf.md)\n- [Linux](notes/linux.md)\n- [Consistency](notes/consistency.md)\n- [Postgres](notes/postgres.md)\n- [Probability theory](notes/prob.md)\n- [Algorithms](https://github.com/marselester/alg)\n- [Primitive types](#primitive-types)\n  - [Bitwise operation](notes/bits.md)\n- [Arrays](#arrays)\n- [Linked lists](#linked-lists)\n- [Sorting](#sorting)\n- [Searching](#searching)\n- [Tests](#tests)\n- [Benchmarks](#benchmarks)\n\n## Primitive types\n\nBitwise operation problems:\n\n- **[count bits](primitive/count_bits.go)**\n  — count the number of bits that are set to 1 in a non-negative integer\n- **[parity](primitive/parity.go)**\n  — compute parity of a non-negative integer (1 if set bits are odd)\n- **[swap bits](primitive/swap_bits.go)**\n  — swap i-th and j-th bits of an integer\n\n## Arrays\n\nArray problems:\n\n- **[even odd](array/even_odd.go)**\n  — reorder an array of integers so that even integers appear first\n- **[Dutch flag](array/dutch_flag.go)**\n  — reorder an array of integers so that integers smaller than pivot appear first,\n    then integers that equal to pivot, and finally integers larger than pivot\n\n## Linked lists\n\nLinked list problems:\n\n- **[reverse](linkedlist/reverse.go)**\n\n## Sorting\n\nSorting problems:\n\n- **[h-index](sorting/h_index.go)**\n  — calculate h-index metric that measures both productivity and citation impact of a researcher\n\n## Searching\n\nSearching problems:\n\n- **[sum 2020](searching/sum2020.go)** (advent of code)\n  — find two/three numbers that add up to 2020\n\n## Tests\n\nEach solution is covered with a few tests.\n\n```sh\n$ go test ./primitive\n```\n\nGo EPI Judge helps to make sure solutions pass all the test cases from EPIJudge repository (csv files).\n\n```sh\n$ git clone https://github.com/stefantds/go-epi-judge.git\n$ git clone https://github.com/adnanaziz/EPIJudge.git\n$ cat \u003e go-epi-judge/config.yml \u003c\u003cCFG\ntestDataFolder: $(pwd)/EPIJudge/test_data\nrunParallelTests: true\nCFG\n$ cd go-epi-judge\n$ # Solution should be placed to ./epi/count_bits/solution.go.\n$ go test ./epi/count_bits\n```\n\n## Benchmarks\n\nBenchmarks help to compare performance of naive and improved solutions.\nFor example, [Bit Twiddling Hacks](https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetNaive)\nshows various techniques to count bits set.\n\n```sh\n$ go test -bench=CountBits ./primitive/\nBenchmarkCountBitsNaive-12       \t138934572\t         8.47 ns/op\nBenchmarkCountBitsKernighan-12    \t250800961\t         4.79 ns/op\n```\n\nIt is recommended to run benchmarks multiple times and check how stable they are\nusing [Benchstat](https://godoc.org/golang.org/x/perf/cmd/benchstat) tool.\n\n```sh\n$ go get golang.org/x/perf/cmd/benchstat\n$ BENCH_COUNT=10\n$ go test -bench=CountBits -count=$BENCH_COUNT ./primitive/ | tee bench.txt\ngoos: darwin\ngoarch: amd64\nBenchmarkCountBitsNaive-12       \t142174494\t         8.35 ns/op\nBenchmarkCountBitsNaive-12       \t143033582\t         8.41 ns/op\nBenchmarkCountBitsNaive-12       \t142639047\t         8.33 ns/op\nBenchmarkCountBitsNaive-12       \t143451723\t         8.39 ns/op\nBenchmarkCountBitsNaive-12       \t143017363\t         8.37 ns/op\nBenchmarkCountBitsNaive-12       \t143151940\t         8.35 ns/op\nBenchmarkCountBitsNaive-12       \t143833944\t         8.41 ns/op\nBenchmarkCountBitsNaive-12       \t143466840\t         8.32 ns/op\nBenchmarkCountBitsNaive-12       \t142059639\t         8.36 ns/op\nBenchmarkCountBitsNaive-12       \t143438925\t         8.44 ns/op\nBenchmarkCountBitsKernighan-12    \t252099921\t         4.75 ns/op\nBenchmarkCountBitsKernighan-12    \t247041158\t         4.74 ns/op\nBenchmarkCountBitsKernighan-12    \t250844809\t         4.73 ns/op\nBenchmarkCountBitsKernighan-12    \t251821089\t         4.75 ns/op\nBenchmarkCountBitsKernighan-12    \t251136150\t         4.81 ns/op\nBenchmarkCountBitsKernighan-12    \t250629847\t         4.77 ns/op\nBenchmarkCountBitsKernighan-12    \t251043451\t         4.74 ns/op\nBenchmarkCountBitsKernighan-12    \t251974099\t         4.77 ns/op\nBenchmarkCountBitsKernighan-12    \t251576733\t         4.75 ns/op\nBenchmarkCountBitsKernighan-12    \t250239159\t         4.74 ns/op\n$ benchstat bench.txt\nname                  time/op\nCountBitsNaive-12     8.37ns ± 1%\nCountBitsKernighan-12  4.75ns ± 1%\n```\n\nNaive solution's mean is 8.37 nanoseconds with ± 1% variation across the samples.\nLet's compare naive to improved solution:\n\n- isolate the samples of each implementation to files `bench_a`, `bench_b`, `bench_...`\n- give the samples the same name `X`\n\n```sh\n$ grep Benchmark bench.txt | sed 's/Benchmark[A-z]*/BenchmarkX/g' | split -l $BENCH_COUNT -a 1 - bench_\n$ benchstat bench_a bench_b\nname  old time/op  new time/op  delta\nX-12  8.37ns ± 1%  4.75ns ± 1%  -43.21%  (p=0.000 n=10+10)\n```\n\nNaive approach is 43.21% slower.\n\nReferences:\n\n- [High performance Go workshop](https://dave.cheney.net/high-performance-go-workshop/dotgo-paris.html#benchmarking)\n- [Benchstat tips](https://github.com/golang/go/issues/23471)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarselester%2Finterview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarselester%2Finterview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarselester%2Finterview/lists"}