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 60 of 377
Program to check pattern of length m repeated K or more times exists or not in Python
Suppose we have an array nums with positive values, we have to find a pattern of length m that is repeated k or more times. Here a pattern is a non-overlapping subarray (consecutive) that consists of one or more values and are repeated multiple times. A pattern is defined by its length and number of repetitions. We have to check whether there exists a pattern of length m that is repeated k or more times or not. So, if the input is like nums = [3, 5, 1, 4, 3, 1, 4, 3, 1, 4, 3, 9, 6, 1], ...
Read MoreProgram to find most visited sector in a circular track using Python
Suppose we have a number n and an array called rounds. We have a circular track which consists of n different sectors labeled from 1 to n. Now consider a race will be held on this track, the race consists of m different rounds. The ith round starts at sector rounds[i - 1] and ends at sector rounds[i]. For example, if the round 1 starts at sector rounds[0] and ends at sector rounds[1]. So we have to find the most visited sectors sorted in ascending order. (The track numbers are in ascending order of sector numbers in the counter-clockwise direction) ...
Read MoreProgram to find number with thousand separator in Python
When working with large numbers, it's often helpful to format them with thousand separators for better readability. Python provides several ways to add commas as thousand separators to numbers. So, if the input is like n = 512462687, then the output will be "512, 462, 687" Method 1: Using Built-in format() Function The simplest approach is to use Python's built-in format() function with the comma separator ? def format_number(n): return format(n, ', ') n = 512462687 result = format_number(n) print(result) print(type(result)) 512, 462, 687 ...
Read MoreProgram to check three consecutive odds are present or not in Python
Suppose we have an array called nums, we have to check whether there are three consecutive odd numbers in nums or not. So, if the input is like nums = [18, 15, 2, 19, 3, 11, 17, 25, 20], then the output will be True as there are three consecutive odds [3, 11, 17]. Algorithm To solve this, we will follow these steps − Get the length of nums If length is 1 or 2, return False (impossible to have 3 consecutive elements) ...
Read MoreProgram to find a good string from a given string in Python
Suppose we have a string s with lower and upper case English letters. We consider a string is a good string which does not have any two adjacent characters s[i] and s[i + 1] where ? 0
Read MoreProgram to find kth missing positive number in an array in Python
Suppose we have an array called nums with positive sorted strictly increasing values, and also have an integer k. We have to find the kth positive integer that is missing from this array. So, if the input is like nums = [1, 2, 4, 8, 12], k = 6, then the output will be 10 because the missing numbers are [3, 5, 6, 7, 9, 10, 11], here the 6th term is 10. Approach To solve this, we will follow these steps − Convert the array to a set for O(1) ...
Read MoreProgram to shuffle string with given indices in Python
Suppose we have a string s and a list of indices ind, they are of same length. The string s will be shuffled such that the character at position i moves to indices[i] in the final string. We have to find the final string. So, if the input is like s = "ktoalak" and ind = [0, 5, 1, 6, 2, 4, 3], then the output will be "kolkata". Original String: Index: Char: 0 ...
Read MoreProgram to count odd numbers in an interval range using Python
Suppose we have two non-negative numbers left and right. We have to find the number of odd numbers between left and right (inclusive). So, if the input is like left = 3, right = 15, then the output will be 7 because there are 7 odd numbers in range, these are [3, 5, 7, 9, 11, 13, 15], there are 7 elements. Algorithm To solve this, we will follow these steps: If left is odd or right is odd, then ...
Read MoreProgram to find maximum how many water bottles we can drink in Python
Suppose there are n number of full water bottles, and we can exchange m empty water bottles for one full water bottle. Drinking a full water bottle makes it an empty bottle. We have to find the maximum number of water bottles we can drink. So, if the input is like n = 9, m = 3, then the output will be 13 because initially we have 9 bottles. After drinking all bottles, we get 9/3 = 3 full bottles from the empty ones. After drinking those 3, we have 3 empty bottles which gives us 1 more full ...
Read MoreProgram to reformat date in YYYY-MM-DD format using Python
Converting date strings from human-readable format like "23rd Jan 2021" to standardized "YYYY-MM-DD" format is a common task in data processing. Python provides several approaches to handle this conversion efficiently. Understanding the Problem We need to parse a date string where: Day includes ordinal suffix (1st, 2nd, 3rd, 4th, etc.) Month is abbreviated (Jan, Feb, Mar, etc.) Year is a four-digit number (1900-2100) The target format is ISO 8601 standard: "YYYY-MM-DD". Method 1: Using String Manipulation This approach splits the date string and manually converts each component ? def solve(date): ...
Read More