주어진 array 에서 최대로 중복되는 index를 제외한 나머지 index의 수를 구하는 문제 solution 1. 중복을 허용하지 않는 hashMap 을 선언. 2. 주어진 arr를 hashMap안에 넣으면서 중복되는 값이 있으면 value의 값이 1씩 증가하게 한다. 3. maximum value의 수를 찾는다. 4. 전체 array길이에서 찾아낸 maximum value를 return한다. Solution 1 -object를 이용하는 traditional way 말고 built-in function 인 Map을 이용하는 방식. function equalizeArray(arr) { //let arrObj = {}; //initialize object which is for hashmap. //but..
Binary Tree(이진트리) 의 node와 그 node의 children을 invert 하는 문제. node뿐 아니라 그 밑에 속해있는 자식들까지 swipe해야하기때문에 recursive function(재귀함수)을 사용해야한다. Solution 1 var invertTree = function(root) { //재귀의 정지값->root가 있을때 까지. if(root){ swap(root); //swipe children invertTree(root.left); //subtree의 children에게도 같은 process적용을 위해 recursive invertTree(root.right); } return root; }; var swap = function(root){ let left = root...
Solution in Javascript const n = 3; function viralAdvertising(n) { let k = 5; let j = 0; let sum = 0; for(let i = 0; i < n; i++){ j = Math.floor(k/2); k = j * 3; sum+=j; } console.log(sum); } viralAdvertising(n); *Use Math.floor() to get quotient. Reference www.hackerrank.com/challenges/strange-advertising/problem
The solution in Javascript I (Failed in HackerRank) sort 를 이용. 순서대로 정렬해준 후에 동일한 값의 (last index - first index) + 1 (0부터 시작하니까) 해외 블로그 접근이 좋긴했지만 결과적으로 HackerRank에서는 fail. const arr = [1, 2, 3, 4, 5, 4, 3, 2, 1, 3, 4, 1] function migratoryBirds(arr) { let bird = 1; let max = bird; //bird 의 시작이 1이라는 것은 at least one bird id는 존재한다는 의미. 나중에 더 큰 값이오면 대체. let result = 0; arr.sort(); //1,1,1,2,2,3,3,3,4,4..
- Total
- Today
- Yesterday
- string class in java
- hackerrank javascript
- math.abs
- code refactoring
- 프로그래머스
- algorithm
- repeat()
- java
- hackerrank solution
- 프로그래머스 알고리즘
- compareTo()
- Collection Framework
- hackerrank javascript solution
- math.max
- easy algorithm
- HackerRank Algorithm
- equals()
- Object type casting
- 알고리즘
- substring()
- rest parameter
- spring boot application
- javascript
- easy javascript algorithm
- C++
- 프로그래머스 알고리즘문제
- hackerrank
- HashMap
- ... in Javascript
- Javascript Algorithm
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |