DEV Community

Bidhubhushan Gahan
Bidhubhushan Gahan

Posted on

1

My DSA Journey

Hey Reader, hope this journey will help you to get a consistent path. I'm Bidhubhushan working as a frontend developer and here is my today's solved DSA questions. 
So, I'm following Striver A-Z sheet. So Let's get started
I'm starting with Arrays and this is the first day of my DSA journey and will end when no questions will be left to solve
Remove Duplicates from the Array #1

/**
 * @param {number[]} nums
 * @return {number}
 */
var removeDuplicates = function (nums) {
    if (nums.length === 0) return;
    let uniqueIndex = 0; // for storing the unique values from the array.
    let arr = []
    for (let i = 1; i < nums.length; i++) {
        if (nums[i] !== nums[uniqueIndex]) {

            uniqueIndex++;
            nums[uniqueIndex] = nums[i]
        }
    }
    return uniqueIndex + 1
};
Enter fullscreen mode Exit fullscreen mode

So this question is the first one which I solved and the question is pretty straight forward where you have to remove the repeating elements from a sorted array.
Move Zeroes to the End #2

/**
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var moveZeroes = function(nums) {
    if(nums.length === 0) return;
    let uniqueIndex = 0;

    for(let i = 0; i<nums.length;i++){
        if(nums[i] !== 0){
            nums[uniqueIndex] = nums[i]
            uniqueIndex++
        }
    }

    for(let j = uniqueIndex;j<nums.length;j++){
        nums[j] = 0;
    }
    return nums
};
Enter fullscreen mode Exit fullscreen mode

You are given an array of integers, your task is to move all the zeros in the array to the end of the array and move non-negative integers to the front by maintaining their order.

Check if the array is Sorted and Rotated #3

/**
 * @param {number[]} nums
 * @return {boolean}
 */
var CheckIfSortedorRotated = function(nums) {
    if(nums.length === 0) return;
    let breakpoint = 0
    for(let i = 0;i<nums.length;i++){
        if(nums[i] > nums[(i+1) % nums.length]){
            breakpoint++
        }
    }
    if(breakpoint > 1){
        return false
    }
    return true
};
Enter fullscreen mode Exit fullscreen mode

The idea is pretty simple here, We will start with the element at the 0th index, and will compare it with all of its future elements that are present in the array.

I'll be posting my everyday journey here, and I will write about** frontend **machine coding as well as for _Javascript _ concepts and questions.

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

If this article connected with you, consider tapping ❤️ or leaving a brief comment to share your thoughts!

Okay