Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 288 of 2109
Program to create a lexically minimal string from two strings in python
Creating a lexically minimal string from two strings involves comparing suffixes and selecting characters that produce the smallest lexicographical result. We compare remaining portions of both strings and choose the character from the string with the lexicographically smaller suffix. So, if the input is like input_1 = 'TUTORIALS', input_2 = 'POINT', then the output will be POINTTUTORIALS. Algorithm Steps If we compare the two strings step-by-step ? TUTORIALS vs POINT TUTORIALS vs OINT → P (choose from input_2) TUTORIALS vs INT → O (choose from input_2) TUTORIALS vs NT → I (choose from input_2) ...
Read MoreProgram to find out the number of shifts required to sort an array using insertion sort in python
Insertion sort moves elements one position at a time to place them in their correct sorted position. Each movement is called a shift. We need to count the total number of shifts required to sort an array using insertion sort. The key insight is that the number of shifts for each element equals the number of larger elements that appear before it in the array. This is called the inversion count. Example Walkthrough Given array [4, 5, 3, 1, 2], let's trace the insertion sort process ? Step 1: [4, 5, 3, 1, 2] → ...
Read MoreAngularJS – isUndefined() method
The isUndefined() method in AngularJS checks if a reference is undefined or not. This method returns true if the reference passed to the function is undefined, otherwise it returns false. Syntax angular.isUndefined(value) Parameters value − The reference to check for undefined status Return Value Returns true if the value is undefined, false otherwise. Example − Check if References are Undefined Create an HTML file in your project directory and copy the following code ? ...
Read MoreAngularJS – forEach() function
The forEach() function in AngularJS uses an iterator to iterate over collections of items, objects, or arrays. The iterator function is called with three parameters: value, key, and obj. value represents the object property or array element key specifies the object property key or array element index obj represents the whole object reference Note that the forEach() function does not iterate over inherited properties. Syntax angular.forEach(obj, iterator, [context]) Parameters obj − The object or array to iterate over iterator − The function to be called for each item context ...
Read MoreProgram to find largest color value in a directed graph in Python
Suppose we have a directed graph with n colored nodes and m different edges. The nodes are numbered from 0 to n-1. We have a string col with lowercase letters, where col[i] represents the color of the ith node in this graph (0-indexed). We also have an edge list where edges[j] = (u, v) represents there is an edge between u and v. A valid path in the graph is a sequence of nodes xi for all i from 1 to k, such that there is a directed edge from xi to xi+1. The color value of the path ...
Read MoreProgram to find minimum interval to include each query in Python
Given a list of intervals and queries, we need to find the smallest interval that contains each query value. For each query, we return the size of the smallest interval that contains it, or -1 if no such interval exists. Problem Understanding Each interval is represented as [left, right] where both endpoints are inclusive. For a query value q, we need to find the interval with minimum size where left ≤ q ≤ right. The size of an interval [left, right] is right - left + 1. Example If the input is intervals = [[2, 5], ...
Read MoreProgram to find closest room from queries in Python
Given an array of rooms where rooms[i] = [roomId_i, size_i] and an array of queries where queries[j] = [preferred_j, minSize_j], we need to find the closest room for each query based on specific criteria. For each query, we need to find a room that: Has size of at least minSize_j |roomId - preferred_j| is minimized In case of tie, choose the room with smallest id Return -1 if no such room exists Example If rooms = [[2, 2], [1, 2], [3, 2]] and queries = [[3, 1], [3, 3], [5, 2]], the output is ...
Read MoreProgram to find maximum building height in Python
Suppose we have a value n and another list of pairs called restrictions. We want to build n new buildings in a city with specific constraints. Buildings are placed in a line and labeled from 1 to n. Each restriction has the format restrictions[i] = (id_i, max_height_i), indicating that building id_i must have height less than or equal to max_height_i. The city has the following height restrictions − The height of each building must be 0 or positive values. First building height must be 0. ...
Read MoreProgram to find XOR sum of all pairs bitwise AND in Python
Suppose we have two arrays arr1 and arr2. The XOR sum of a list is the bitwise XOR of all its elements. If the list has only one element, then its XOR sum will be the element itself. Now, consider a list containing the result of arr1[i] AND arr2[j] (bitwise AND) for every index pair (i, j) where 0 ≤ i < length of arr1 and 0 ≤ j < length of arr2. We have to find the XOR sum of that list. So, if the input is like arr1 = [5, 3, 4] and arr2 = [2, 6], ...
Read MoreProgram to find minimum number of operations to make string sorted in Python
Suppose we have a string s. We have to perform the following operation on s until we get a sorted string − Select largest index i such that 1 ≤ i < length of s and s[i] < s[i - 1]. Select largest index j such that i ≤ j < length of s and s[k] < s[i - 1] for all the possible values of k in the range [i, j] inclusive. Exchange two characters at indices i - 1 and j. ...
Read More