Skip to content

Commit 15aa186

Browse files
committed
pb 15
1 parent 0d747da commit 15aa186

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,16 @@ The area of a circle is defined as `πr²`. Estimate `π` to 3 decimal places us
217217
Hint: The basic equation of a circle is `x² + y² = r²`.
218218

219219
### Solution
220-
[Python](pb14/answer.py) (19:37)
220+
[Python](pb14/answer.py) (19:37)
221+
222+
223+
---
224+
225+
## 15
226+
> This problem was asked by Dropbox.
227+
228+
Spreadsheets often use this alphabetical encoding for its columns: "A", "B", "C", ..., "AA", "AB", ..., "ZZ", "AAA", "AAB", ....
229+
Given a column number, return its alphabetical column id. For example, given 1, return "A". Given 27, return "AA".
230+
231+
### Solution
232+
[JS](pb15/answer.js) (9:18)

pb15/Problem.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
> This problem was asked by Dropbox.
2+
3+
Spreadsheets often use this alphabetical encoding for its columns: "A", "B", "C", ..., "AA", "AB", ..., "ZZ", "AAA", "AAB", ....
4+
Given a column number, return its alphabetical column id. For example, given 1, return "A". Given 27, return "AA".

pb15/answer.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
3+
4+
5+
const getAlphaColId = (numId) => {
6+
7+
let b26 = numId.toString(26);
8+
9+
let split = b26.split("");
10+
11+
return split.map(id => alphabet.charAt(id - 1)).join("");
12+
};
13+
14+
console.log(getAlphaColId(27));

0 commit comments

Comments
 (0)