Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit 7997484

Browse files
authored
W1/7 - Sparse Array (#152)
There's a bit more to this PR than just the Elixir challenge. The global readme had a big update to link to the PR's for each challenge. That's a nicer pattern than the per week readme which is cumbersome and invisible. This closes #117
1 parent 3f25ea8 commit 7997484

5 files changed

Lines changed: 140 additions & 2 deletions

File tree

README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,62 @@
44

55
This repo’s layout isn’t idiomatic to any one language — it’s a mix of Elixir, Go, Python, and TypeScript.
66

7+
## Quality
8+
9+
When I first started these challenges, I was in a teaching job and I was completing them between classes and during times when my students had been tasked and was literally doing nothing. These challenges go all the way up to week 4/5. These are not my best work, I was more interested in making stuff work. However, when I quit the teaching job and was able to sit down and focus on quality, I started everything again. I went over the week one python work and moved everything to a standard that any colleage, customer or employer would be more than happy with.
10+
11+
So below is a table of challenges that I consider to be complete, and to have been completed to a high professional standard that you'd expect from any work I was doing. Inline docs, testing, linting, static code analysis, CI/ CD etc. Each PR for each challenge is listed below. If it's not in this table and it's in the repo, consider it a working draft of my thoughts.
12+
13+
14+
### Week 1
15+
16+
| | | Python | Elixir | TypeScript | Go |
17+
|-|- |- |- |- |- |
18+
| W1/1| Plus Minus |[![PR](img/pr.svg)][11py]|[![PR](img/pr.svg)][11ex]||[![PR](img/pr.svg)][11go]|
19+
| W1/2| Mini Max Sum |[![PR](img/pr.svg)][12py]|[![PR](img/pr.svg)][12ex]||[![PR](img/pr.svg)][11go]|
20+
| W1/3| Time Conversion |[![PR](img/pr.svg)][13py]|[![PR](img/pr.svg)][13ex]|[![PR](img/pr.svg)][13ts]|[![PR](img/pr.svg)][11go]|
21+
| W1/4| Breaking Records |[![PR](img/pr.svg)][14py]|[![PR](img/pr.svg)][14ex]|||
22+
| W1/5| Camel Case |[![PR](img/pr.svg)][15py]|[![PR](img/pr.svg)][15ex]|||
23+
| W1/6| Divisible Sum Pairs |[![PR](img/pr.svg)][16py]|[![PR](img/pr.svg)][16ex]|||
24+
| W1/7| Sparse Array |[![PR](img/pr.svg)][17py]|[![PR](img/pr.svg)][17ex]|||
25+
26+
[11py]: https://github.com/treejamie/hackerrank-90days/pull/108
27+
[12py]: https://github.com/treejamie/hackerrank-90days/pull/108
28+
[13py]: https://github.com/treejamie/hackerrank-90days/pull/109
29+
[14py]: https://github.com/treejamie/hackerrank-90days/pull/111
30+
[15py]: https://github.com/treejamie/hackerrank-90days/pull/113
31+
[16py]: https://github.com/treejamie/hackerrank-90days/pull/114
32+
[17py]: https://github.com/treejamie/hackerrank-90days/pull/115
33+
34+
[11ex]: https://github.com/treejamie/hackerrank-90days/pull/103
35+
[12ex]: https://github.com/treejamie/hackerrank-90days/pull/138
36+
[13ex]: https://github.com/treejamie/hackerrank-90days/pull/141
37+
[14ex]: https://github.com/treejamie/hackerrank-90days/pull/142
38+
[15ex]: https://github.com/treejamie/hackerrank-90days/pull/148
39+
[16ex]: https://github.com/treejamie/hackerrank-90days/pull/151
40+
[17ex]: https://github.com/treejamie/hackerrank-90days/pull/152
41+
42+
[11ts]: #
43+
[12ts]: #
44+
[13ts]: https://github.com/treejamie/hackerrank-90days/pull/136
45+
[14ts]: #
46+
[15ts]: #
47+
[16ts]: #
48+
[17ts]: #
49+
50+
[11go]: https://github.com/treejamie/hackerrank-90days/pull/102
51+
[12go]: https://github.com/treejamie/hackerrank-90days/pull/105
52+
[13go]: https://github.com/treejamie/hackerrank-90days/pull/147
53+
[14go]: #
54+
[15go]: #
55+
[16go]: #
56+
[17go]: #
57+
58+
### Week 2
59+
60+
I'll update this README with week two once I've completed all the challenges in all the languages from week one.
61+
62+
763
Spot something I could improve? Open an issue and point it out — that would be swell.
864

965
## 🙋 Why?
@@ -12,7 +68,7 @@ The HackerRank 90-day course was designed as a three-month prep for recruitment
1268

1369
What I’m noticing, though, is that it’s also improving my authoring skills more broadly.
1470

15-
I started in January. At first, I just wanted to get through it in Python — a collection of scripts to store solutions. Then I added per-file unit testing. Then I started doing the challenges in different languages, and it evolved from there. Now it’s basically a code dojo for me, where I’m free to pick a task and write it up in a bunch of languages.
71+
I started in January. At first, I just wanted to get through it in Python — a collection of scripts to store solutions. Then I added per-file unit testing. Then I started doing the challenges in different languages, and it evolved from there. Now it’s basically a code dojo for me, where I’m working through each challenge in each language. I'm learning a lot. Especially about parsing text files (_test cases_).
1672

1773
I’ll be very pleased if I complete these challenges by the end of 2025 in four languages: Python, Elixir, Go, and TypeScript. The aim is to get a nice 25% language distribution across the repository and to demonstrate competence in basic project layout, standard libraries, testing methodologies, and — most importantly — low-complexity solutions.
1874

img/pr.svg

Lines changed: 11 additions & 0 deletions
Loading

w1/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ Given a list of input strings and a set of query strings, return the number of t
7575

7676
| Python | Elixir | TypeScript | Go |
7777
|--------|--------|------------|----|
78-
|| |||
78+
|| |||

w1/sparsearray.ex

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
defmodule HackerRank.W1.SparseArray do
2+
@moduledoc """
3+
Sparse Arrays - Challenge 7, Week 1.
4+
<https://www.hackerrank.com/challenges/three-month-preparation-kit-sparse-arrays/problem>
5+
"""
6+
7+
@doc """
8+
Return a list of counts for how often each query appears in the input strings.
9+
10+
## Parameters:
11+
strings (list[str]): a list of strings
12+
queries (list[str]): a list of queries
13+
14+
## Returns:
15+
list[int]: counts for how often each query appears in the input strings.
16+
17+
## Example:
18+
iex> SparseArray.challenge(["aba", "baba", "aba", "xzxb"], ["aba", "xzxb", "ab"])
19+
[2, 1, 0]
20+
"""
21+
@spec challenge([String.t()], [String.t()]) :: [integer()]
22+
def challenge(strings, queries) do
23+
queries
24+
|> Enum.map(fn query ->
25+
# r = Regex.compile!("^#{query}$")
26+
# Enum.count(strings, fn s -> Regex.match?(r, s) end)
27+
# Regexs work, but the above regex is effectively checking equality
28+
# So instead, just compare strings. Same thing, faster result.
29+
Enum.count(strings, fn s -> s == query end)
30+
end)
31+
end
32+
33+
end

w1/sparsearray_test.exs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
defmodule HackerRank.W1.SparseArrayTest do
2+
use ExUnit.Case
3+
alias HackerRank.Test.Helper
4+
alias HackerRank.W1.SparseArray
5+
doctest HackerRank.W1.SparseArray
6+
7+
8+
@pattern ~w"w1/tc/7_*.txt"
9+
10+
test "run the tests" do
11+
Helper.test_all(@pattern, &parse_args/1, &parse_expected/1 )
12+
|> Enum.each(fn [[strings, queries], expected] ->
13+
assert SparseArray.challenge(strings, queries) == expected
14+
end)
15+
end
16+
17+
18+
def parse_args(raw) do
19+
# get the data out of a list
20+
# get the strings
21+
[take | list] = raw
22+
take = String.to_integer(take)
23+
strings = Enum.take(list, take)
24+
25+
# get the queries
26+
[take | list ] = Enum.drop(list, take)
27+
queries = Enum.take(list, String.to_integer(take))
28+
29+
# done
30+
[strings, queries]
31+
end
32+
33+
def parse_expected(raw) do
34+
# Just need to convert the list of strings to integers
35+
Enum.map(raw, &String.to_integer/1)
36+
end
37+
38+
end

0 commit comments

Comments
 (0)