DEV Community

Bidhubhushan Gahan
Bidhubhushan Gahan

Posted on

DSA Journey #day2

So today I’ll solve some basic array questions as follows and I’ll share the code that I have done. Let’s get started on my day 2 journey.

Find the Missing number in the array #1
for this question I have implemented the logic as follows, as it it a very basic and straightforward question.


//122 / 122 testcases passed

/**
 * @param {number[]} nums
 * @return {number}
 */
var missingNumber = function (nums) {
    if (nums.length === 0) return;
    nums = nums.sort((a, b) => a - b)
    for (let i = 0; i <= nums.length; i++) {
        if (nums[i] !== i) {
            return i;
        }
    }
};
Enter fullscreen mode Exit fullscreen mode

Max Consecutive Ones #2 — Leetcode — 485
Given a binary array nums, return the maximum number of consecutive 1's in the array.

/**
 * @param {number[]} nums
 * @return {number}
 */
var findMaxConsecutiveOnes = function (nums) {
    if (nums.length === 0) return;

    let counter = 0;
    let max = 0;

    for (let i = 0; i < nums.length; i++) {
        if (nums[i] === 1) {
            counter++;
            if (counter > max) {
                max = counter
            }
        } else {
            counter = 0
        }
    }
    return max
};
Enter fullscreen mode Exit fullscreen mode

Thanks for visiting
Bidhubhushan Gahan
7609074970

Github - https://github.com/Bidhu1024
LinkedIn - https://www.linkedin.com/in/bidhu05/
Leetcode - https://leetcode.com/u/Bidhubhushan_Gahan/

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay