Found 25 Articles for Coding Practice

Minimum sum of differences with an element in an array

AYUSH MISHRA
Updated on 27-Mar-2025 19:33:41

787 Views

Problem Statement In this problem, we are given an array of integers, and we have to select a particular element from the array such that the sum of absolute differences between that element and all other elements is minimized. Example 1 Input: arr = [3, 1, 2, 5, 4] Output: 6 Explanation: If we select 3 as the element, the sum of differences is: |3-1| + |3-2| + |3-3| + |3-4| + |3-5|= 2 + 1 + 0 + 1 + 2 = 6 ... Read More

Sort an array which contain 1 to n values

AYUSH MISHRA
Updated on 19-Mar-2025 18:54:21

1K+ Views

Sorting an array containing values from 1 to n means arranging the integers in their natural ascending order. This type of sorting problem is commonly encountered in competitive programming (for solving complex problems), where the array is guaranteed to have integers ranging from 1 to n. In this article, we will explore various approaches to solving this problem. In this problem, we are given an array containing values ranging from 1 to n in random order. Our goal is to sort the array in ascending order. Example 1 Input: int array[] = {3, 1, 2, ... Read More

Missing Number in an array in O(1) Time Complexity

AYUSH MISHRA
Updated on 30-Dec-2024 19:22:27

3K+ Views

Problem Description We are given an array that contains numbers from 1 to n, and one number is missing between the given numbers from 1 to n. We have to return the missing number in O(1) time complexity. In this problem, we are going to discuss how we can find the missing number in an array. Example 1 Input: array = {1, 2, 3, 5, 6, 7} Output: 4 Explanation From 1 to 7, the number 4 is missing in the given array. Example 2 ... Read More

How to Prepare for Coding Interviews?

Swaroop N
Updated on 27-Dec-2024 13:02:10

27 Views

Getting hired by Top IT companies might be stressful, particularly when it comes to the coding job interview. However, don’t panic! It doesn’t matter if you are a novice coder or someone with years of experience, all coding interviews can be managed easily if you have the necessary preparation. This tutorial will offer a concise description of the fundamental skills and behaviors needed to succeed1. Make Sense of the Interview OutlineAchieving success in a coding interview with a target company begins with the client understanding the workflow. Here is something to look out forDummy Screening: One of the reviews and a ... Read More

Benefits of ipsum or dummy text for developers

Harleen Kaur
Updated on 11-Dec-2024 11:54:17

2K+ Views

Ipsum, also known as dummy text is an important tool for developers during planning and development stage. Teams can concentrate on format, features, and user satisfaction without being restricted to or inaccessible textual content due to its impartial content placeholder. This approach ensures clear communication among developers, designers, and stakeholders while simplifying the processes. Benefits of Ipsum or Dummy Text for DevelopersIpsum or dummy text provides the following benefits to developers -  Pays Attention to Visual DesignDesigners and developers can focus on a project's visual elements by using placeholder text. It is possible to improve font patterns, sizes, alignment, and ... Read More

check if a given array represent min-heap or not

AYUSH MISHRA
Updated on 22-Nov-2024 15:00:07

3K+ Views

A Heap is a Tree-based data structure in which the tree is a complete binary tree. Binary heap is of two types max heap and min heap. A min-heap is a tree-like structure in which the value of the parent node should always be less than both of its left and right child and follow this property recursively for all nodes until it reaches to leaf node. According to this property, the root node of the min-heap has the smallest value. In this article, we are going to check whether an array represents a min-heap or not. Problem Description We ... Read More

Longest consecutive subsequence in C++

Jiya Garg
Updated on 02-Sep-2024 18:02:19

112 Views

Given an array of integers, determine the length of the longest subsequence where the elements are consecutive integers, regardless of their order within the subsequence. Input  arr = {100, 4, 200, 1, 3, 2} Output  Length of the longest consecutive sequence is: 4 Different approaches for longest consecutive subsequence The following are the approaches to get longest consecutive subsequence By sorting the Array By using Set Approach 1: By Sorting the ArrayBelow are the steps to get the longest consecutive subsequence in C++ using Array Sort ... Read More

Program to find a Score of a String

Revathi Satya Kondra
Updated on 23-Jul-2024 11:06:32

409 Views

The Score of a String is a concept which is used to calculate the score based on the sum of the absolute differences between the ASCII values of adjacent characters in the string. Problem Statement Given a string s, calculate the score of the string. The score is defined as the sum of the absolute differences between the ASCII values of adjacent characters. Example Scenario 1 Input: s="abc" Output: 2 The ASCII values of the characters in s are 'a' = 97, 'b' = 98, 'c' = 99. So, the score of s = |97-98|+|98-99|= 1+1 ... Read More

Program to find the Maximum Prime Difference

Revathi Satya Kondra
Updated on 23-Jul-2024 11:15:12

117 Views

The Maximum Prime Difference is a problem used to determine the largest difference between indices of two prime numbers in a given array. Problem Statement Here, we have given an array of integers as nums. our task is to find the maximum prime difference between the indices of any two prime numbers in an array. In the given array if we have only one prime number then it returns 0 and if no prime number returns -1. Example Scenario 1 Input: arr = [11, 4, 7, 6, 13] Output: 4 The prime numbers are 11 (index 0), ... Read More

Minimum Operations to Make Median of Array Equal to K

Revathi Satya Kondra
Updated on 23-Jul-2024 11:14:32

206 Views

The problem “Minimum Operations to Make the Median of the Array Equal to K” is used to adjust the elements of an integer array so that its median becomes equal to a given value k. In one operation, you can increase or decrease any element by 1. Problem Statement The goal is to find the minimum number of such operations to make the median of the array equal to K. The median of an array is the middle element when the array is sorted in non-decreasing order. The larger one is considered the median if there are two middle ... Read More

Advertisements