Binary Search

    LeetCode / Binary Search / 1608번 / Special Array With X Elements Greater Than or Equal X / JS

    양수만 존재하는 nums 배열이 주어진다.x를 찾아서 반환하면 되는 문제인데, 이 x의 조건은 다음과 같다.nums 배열안에 존재하지 않는 수이다.x이상의 수가 정확히 x개 존재해야 한다.만약 x가 존재할 수 없다면 -1을 반환하면 된다. [ 풀이 1 - 단순 구현 ]/** * @param {number[]} nums * @return {number} */const specialArray = (nums) => { const sortedNumberList = [...nums].sort((a, b) => a - b); const min = 0; const max = sortedNumberList.at(-1); for (let x = max; x > min; x--) { let count = 0;..

    LeetCode / Binary Search / 33번 / Search in Rotated Sorted Array / JS

    Search in Rotated Sorted Array - LeetCode Can you solve this real interview question? Search in Rotated Sorted Array - There is an integer array nums sorted in ascending order (with distinct values). Prior to being passed to your function, nums is possibly rotated at an unknown pivot index k (1 정렬된 배열이 원형큐처럼 몇번 회전이 되었을지 알 수 없는 배열에서 target 값을 찾는 문제이다. /** * @param {number[]} nums * @p..

    LeetCode / Binary Search / 74번 / Search a 2D Matrix / JS

    Search a 2D Matrix - LeetCode Can you solve this real interview question? Search a 2D Matrix - You are given an m x n integer matrix matrix with the following two properties: * Each row is sorted in non-decreasing order. * The first integer of each row is greater than the last integer leetcode.com 주어진 2차원 배열에서 target 값이 존재하는지 찾는 문제이다. 그냥 간단히 할 수도 있겠지만... topic이 Binary Sea..

    LeetCode / Binary Search / 278번 / First Bad Version / JS

    First Bad Version - LeetCode Can you solve this real interview question? First Bad Version - You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed base leetcode.com 나쁜 버전인지 판단해서 boolean 값으로 반환하는 api가 isBadVersion 라는 이름으로 주어진다. 만약 n번째 버전이 나쁜..

    LeetCode / Binary Search / 704번 / Binary Search / JS

    Binary Search - LeetCode Can you solve this real interview question? Binary Search - Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. leetcode.com 주어진 nums 배열에서 target의 값이 몇번째 인덱스에 존재하는지 이분탐색으로 찾는 문제이다. /** * @param {number[]}..