You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Separate a mobile number given in an international format into parts countrycode, number
1020
+
I think its a nice example about a problem which can be solved in a number of ways, and still being very precise and compact in description
1021
+
mikamoilanen — 3:53 PM
1022
+
Start with a list of few countrycodes, like +1, +358
1023
+
Given a phone number eg "+358451252855", separate it into two parts: +358 and 451252855
1024
+
The essiest way is to sort country codes by lenght, longest first, and loop through them by asking if the phonenumber.startsWith(cc)
1025
+
(this works as codes are common-prefix-free)
1026
+
mikamoilanen — 4:01 PM
1027
+
Another solution creates a nice opportunity to introduce creating your own datastructure for more efficient solution: Build a tree out of the codes, where each number has N childs, and traverse throught that tree number-by-number of the phonenumber
1028
+
THEN you could even introduce packing the data as bitvectors in order to have even more compact data structure
Copy file name to clipboardExpand all lines: src/first_steps.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,12 +34,12 @@ This bit of magic here - `IO.println` - is a "statement" that "prints" the text
34
34
35
35
**print** with new **l**i**n**e.
36
36
37
-
If you were to replace it with `System.out.print`, then the output would lack that new line. This makes the following program be functionally identical to the first.
37
+
If you were to replace it with `IO.print`, then the output would lack that new line. This makes the following program be functionally identical to the first.
38
38
39
39
```java
40
40
~void main() {
41
-
System.out.print("Hello, ");
42
-
System.out.print("World");
41
+
IO.print("Hello, ");
42
+
IO.print("World");
43
43
IO.println("!");
44
44
~}
45
45
```
@@ -48,8 +48,8 @@ Which, when we add back `void main()`, looks like this.
0 commit comments