본문 바로가기 메뉴 바로가기

Studying programming

프로필사진
  • 글쓰기
  • 관리
  • 태그
  • 방명록
  • RSS

Studying programming

검색하기 폼
  • Jimin's Programming (194)
    • Algorithms (54)
    • JavaScript (16)
    • Vue.js (3)
    • Node.js (3)
    • React.js (7)
    • React Native (0)
    • Spring Boot (13)
    • JAVA (58)
    • C++ (17)
    • Programming (19)
    • Computer basics (4)
  • 방명록

HackerRank Algorithm (17)
Equalize the Array

주어진 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..

Algorithms 2020. 12. 11. 00:10
Invert Binary Tree

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...

Algorithms 2020. 11. 30. 22:51
Sequence Equation

Solution in Javascript const p = [4, 2, 5, 1, 3]; function permutationEquation(p) { const arr=[]; for (let i = 1; i

Algorithms 2020. 10. 30. 15:20
Viral Advertising

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

Algorithms 2020. 10. 22. 19:31
Migratory Birds

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..

Algorithms 2020. 10. 1. 23:50
Utopian Tree

Solution in JavaScript const n = 5; function utopianTree(n) { let cycle = 1; let height = 1; while (cycle

Algorithms 2020. 10. 1. 21:16
이전 1 2 3 다음
이전 다음
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
  • HashMap
  • hackerrank javascript solution
  • Collection Framework
  • rest parameter
  • repeat()
  • string class in java
  • code refactoring
  • easy algorithm
  • javascript
  • equals()
  • algorithm
  • math.max
  • compareTo()
  • Object type casting
  • 프로그래머스 알고리즘문제
  • spring boot application
  • hackerrank
  • java
  • hackerrank solution
  • C++
  • math.abs
  • substring()
  • 프로그래머스
  • ... in Javascript
  • easy javascript algorithm
  • hackerrank javascript
  • HackerRank Algorithm
  • 알고리즘
  • 프로그래머스 알고리즘
  • Javascript Algorithm
more
«   2025/08   »
일 월 화 수 목 금 토
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 29 30
31
글 보관함

Blog is powered by Tistory / Designed by Tistory

티스토리툴바