Aayush Mohan Sinha

Aayush Mohan Sinha

89 Articles Published

Articles by Aayush Mohan Sinha

Page 3 of 9

In-place Algorithm to Move Zeros to End of List in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 1K+ Views

Moving zeros to the end of an array while maintaining the order of non-zero elements is a common programming problem in JavaScript. This article explores two efficient approaches to solve this problem: the in-place two-pointer method and the count-and-fill approach. Problem Statement Given an array containing integers including zeros, we need to move all zeros to the end while preserving the relative order of non-zero elements. The goal is to achieve this efficiently, ideally in a single pass through the array. For example, given the input array: [2, 5, 0, 1, 0, 8, 0, 3] ...

Read More

Removing punctuations from a string using JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 2K+ Views

Removing punctuation from strings is a common task in text processing applications. JavaScript provides several effective methods to accomplish this, from regular expressions to iterative approaches. Problem Statement Create a JavaScript function that removes all punctuation marks from a given string while preserving letters, numbers, and spaces. Sample Input: Hello, world! How's everything going? Sample Output: Hello world Hows everything going Using Regular Expression (Recommended) Regular expressions provide the most efficient way to remove punctuation. The pattern /[^\w\s]/g matches any character that isn't a word character (letters, digits) or whitespace. ...

Read More

Checking if a string can be made palindrome in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 887 Views

In JavaScript, determining if a string can be made into a palindrome by removing at most one character is a common algorithmic problem. A palindrome reads the same forwards and backwards, like "racecar" or "level". Problem Statement Given a string, we need to check if it can become a palindrome by removing at most one character. The function should return true if possible, false otherwise. Sample Input: "racecar" Sample Output: true Using Two Pointers (Recommended) The most efficient approach uses two pointers starting from both ends of the string, moving towards the center while comparing ...

Read More

Deleting occurrences of an element if it occurs more than n times using JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 354 Views

In JavaScript, managing array elements with excessive occurrences is a common data manipulation task. This article demonstrates how to delete elements that appear more than a specified number of times while preserving the original order. Problem Statement Given an array and a positive integer n, write a JavaScript function that removes elements if they occur more than n times. The first n occurrences should be kept, and any additional occurrences should be removed. Sample Input: const arr = [1, 2, 3, 1, 2, 1, 1, 3]; const n = 2; Sample Output: ...

Read More

Constructing an array of smaller elements than the corresponding elements based on input array in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 193 Views

In JavaScript, constructing an array where each element represents the count of smaller numbers to the right is a common algorithmic problem. This technique is useful for data analysis, ranking systems, and competitive programming challenges. Problem Statement Given an input array of numbers, create an output array where each element represents the count of numbers smaller than the current element and located to its right in the input array. Sample Input: Input Array: [5, 2, 6, 1] Sample Output: Output Array: [2, 1, 1, 0] For element 5: two ...

Read More

Function that returns the minimum and maximum value of an array in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 910 Views

Finding the minimum and maximum values in an array is a fundamental task in JavaScript programming. Whether you're analyzing data, implementing algorithms, or building interactive applications, having efficient methods to determine array extremes is essential. Problem Statement Create a JavaScript function that takes an array of numbers as input and returns both the minimum and maximum values. The function should handle arrays of any length efficiently. Sample Input: const inputArray = [5, 2, 9, 1, 7, 4]; Sample Output: const minValue = 1; const maxValue = 9; Using Math.min() and Math.max() ...

Read More

How to Create Image Accordion using HTML and CSS?

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 814 Views

An image accordion is a popular web interface element that allows users to expand and collapse image sections for an interactive browsing experience. This technique creates a smooth, space-efficient way to display multiple images where only one section is fully visible at a time. Syntax .accordion-container { display: flex; } .accordion-item { flex: 1; transition: all 0.3s ease; cursor: pointer; } .accordion-item:hover { flex: expanded-ratio; } What is an Accordion? An accordion ...

Read More

How to define word-break property to allow words to be continued to the next line in CSS?

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 343 Views

The CSS word-break property controls how words should break when they reach the edge of their container. This property is essential for maintaining readable text layouts, especially when dealing with long words or narrow containers that might cause text overflow. Syntax selector { word-break: value; } Possible Values ValueDescription normalDefault behavior - words break at natural break points break-allWords can break at any character to prevent overflow keep-allPrevents word breaks for CJK (Chinese, Japanese, Korean) text Example: Using break-all Value The following example demonstrates how word-break: ...

Read More

How to define two column layout using flexbox?

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 5K+ Views

To create a two column layout using flexbox can be so easy if you have the knowledge of CSS display property. Flexbox is a layout model in CSS that provides an efficient and flexible way to arrange and distribute space between items within a container. It arranges elements in a single dimension, either horizontally or vertically, within a container. To know more about the CSS Flexbox Layout visit the attached link. Imagine we have parent div and inside that div we have two child div all we have to do is place those child div side by horizontally. ...

Read More

How to define the shape of the corners is animatable using CSS?

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 174 Views

The CSS border-radius property can be animated to create smooth transitions between different corner shapes. This technique allows you to transform elements from sharp corners to rounded or circular shapes when users interact with them. Syntax selector { border-radius: initial-value; transition: border-radius duration; } selector:hover { border-radius: final-value; } Approach To create animatable corner shapes, follow these steps − Create an HTML element and assign it a class name Set the initial border-radius value (usually 0% for sharp corners) ...

Read More
Showing 21–30 of 89 articles
« Prev 1 2 3 4 5 9 Next »
Advertisements