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
Programming Articles
Page 504 of 2547
Program 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 MoreHow to create charts in excel using Python with openpyxl?
In this tutorial, we'll create Excel charts using Python's openpyxl module. We'll build a spreadsheet with tennis players' Grand Slam titles and create a bar chart to visualize the data. What is openpyxl? The openpyxl module is a powerful Python library for working with Excel files (.xlsx). Unlike the xlrd module which is read-only, openpyxl supports both reading and writing operations, making it ideal for creating charts and manipulating Excel data. Installation First, install the openpyxl module ? pip install openpyxl Creating a Spreadsheet with Data Let's start by creating a ...
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 MoreHow to interpolate data values into strings in Python?
We can interpolate data values into strings using various formats. We can use this to debug code, produce reports, forms, and other outputs. In this topic, we will see three ways of formatting strings and how to interpolate data values into strings. Python has three ways of formatting strings: % − old school (supported in Python 2 and 3) format() − new style (Python 2.6 and up) f-strings − newest style (Python 3.6 and up) Old Style: % Formatting The old style of string formatting has the form format_string % data. The format strings ...
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 More