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
Articles by Arnab Chakraborty
Page 100 of 377
Program to find airports in correct order in Python?
Finding airports in correct order from a shuffled list of flights is a classic graph traversal problem. We need to reconstruct the travel itinerary by finding an Eulerian path through the flight connections, ensuring lexicographical ordering when multiple valid paths exist. Algorithm Overview The solution uses Hierholzer's algorithm to find an Eulerian path in a directed graph ? Build adjacency list from flight pairs Track in-degree and out-degree for each airport Find starting airport (out-degree - in-degree = 1, or lexicographically smallest) Use DFS to traverse and build the path Return reversed path for correct order ...
Read MoreProgram to check whether we can make k palindromes from given string characters or not in Python?
Suppose we have a string s and another number k, we have to check whether we can create k palindromes using all characters in s or not. So, if the input is like s = "amledavmel" k = 2, then the output will be True, as we can make "level" and "madam". Algorithm To solve this, we will follow these steps − d := a map where store each unique characters and their frequency cnt := 0 for each key in d, do if d[key] is odd, then cnt := cnt + 1 ...
Read MoreProgram to find minimum number of Fibonacci numbers to add up to n in Python?
Suppose we have a number n; we have to find the minimum number of Fibonacci numbers required to add up to n. This problem uses a greedy approach where we always pick the largest possible Fibonacci number. So, if the input is like n = 20, then the output will be 3, as we can use the Fibonacci numbers [2, 5, 13] to sum to 20. Algorithm To solve this, we will follow these steps − Initialize result counter to 0 Generate Fibonacci numbers up to n ...
Read MoreProgram to perform excel spreadsheet operation in Python?
Excel spreadsheets contain cells with values, formulas, or cell references. In Python, we can simulate this by processing a 2D matrix where each cell can contain a number, a cell reference (like "B1"), or a formula (like "=A1+A2"). Problem Understanding Given a 2D matrix representing an Excel spreadsheet, we need to evaluate all formulas and cell references to get the final computed values. Columns are labeled A, B, C... and rows are numbered 1, 2, 3... Input Matrix Output Matrix B170 35=A1+A2 770 3510 ...
Read MoreProgram to count number of operations required to convert all values into same in Python?
Given a list of integers, you can perform the following operation: pick the largest number and turn it into the second largest number. We need to find the minimum number of operations required to make all integers the same in the list. For example, if the input is nums = [5, 9, 2], the output will be 3. Here's how: pick 9 first, then make it 5, so array becomes [5, 5, 2]. Then pick 5 and make it 2, getting [5, 2, 2]. Again pick 5 and convert it into 2, resulting in [2, 2, 2]. Algorithm ...
Read MoreProgram to check whether we can make group of two partitions with equal sum or not in Python?
Suppose we have a list of numbers called nums, we have to check whether we can partition nums into two groups where the sum of the elements in both groups are the same. So, if the input is like nums = [2, 3, 6, 5], then the output will be True, as we can make groups like: [2, 6] and [3, 5]. Algorithm To solve this, we will follow these steps − total := sum of all elements in nums if total is odd, then ...
Read MoreProgram to enclose pattern into bold tag in Python?
When working with text processing, you often need to highlight specific patterns by wrapping them in HTML tags. This problem involves finding all occurrences of given patterns in a text and enclosing them in tags, while merging overlapping or adjacent patterns. Problem Understanding Given a text string and a list of patterns, we need to: Find all substrings that match any pattern Wrap matching substrings in and tags Merge overlapping or adjacent bold regions Algorithm Steps The solution uses a boolean array to track which characters should be bold: ...
Read MoreProgram to find number of distinct coin sums we can make with coins and quantities in Python?
Suppose we have a list of values called coins and another list called quantities of the same length. The value of ith coin is coins[i] and we currently have quantities[i] number of ith coin. We have to find number of distinct coin sum values we can get by using non-empty group of these coins. So, if the input is like coins = [1, 2, 5] and quantities = [1, 2, 1], then the output will be 10, as we can have the following distinct coin sums: [1] = 1, [2] = 2, [1, 2] = 3, [2, 2] = ...
Read MoreProgram to find a pair (i, j) where nums[i] + nums[j] + (i -j) is maximized in Python?
Given a list of numbers, we need to find a pair (i, j) where i < j such that nums[i] + nums[j] + (i - j) is maximized. Since i < j, the term (i - j) will always be negative, so we're essentially looking for nums[i] + nums[j] - (j - i). For example, if nums = [6, 6, 2, 2, 2, 8], selecting indices i=0 and j=1 (both values are 6) gives us: 6 + 6 + (0 - 1) = 11. Algorithm Approach The key insight is to rearrange the expression nums[i] + nums[j] ...
Read MoreProgram to find length of longest diminishing word chain in Python?
Suppose we have a list of valid words and a string s. We need to find the length of the longest chain of diminishing words that can be generated by starting at s and removing single letters while keeping valid words. A diminishing word chain is formed by repeatedly removing one character from a word to create another valid word from the given list. Example If the input is words = ["lii", "limit", "limi", "li", "coffee", "jug", "pool", "type"] and s = "limit", the output will be 4. We can form the chain: "limit" → "limi" → ...
Read More