Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 964 of 3363
201 Views
Suppose we have a list called costs. Where costs[i] has [c1, c2] indicates that for person i it costs c1 amount to reach city 0 and costs c2 amount to reach city 1. We want the same number of people to go to city 0 as city 1, we have to find the minimum cost required.So, if the input is like costs = [[2, 6], [10, 3], [4, 9], [5, 8]], then the output will be 17, because person 0 and 2 will go to city 0 and person 1 and 3 to city 1, so for city 0, the ... Read More
251 Views
Suppose we have two numbers k and target. Now consider Amal and Bimal are playing a game. In each round Amal picks a number from 1 to k to add to the total score that initially starts from 0. Whoever crosses the total to target wins. Amal always plays first, we have to check whether he can force a win if both of them plays optimally.So, if the input is like k = 5 target = 10, then the output will be True, as if Amal picks 4 first, then whether Bimal picks 1, 2, ..., or 5, Amal can ... Read More
266 Views
Suppose we have a list of numbers called nums. We have to find the index of every peak element in the nums, sorted in ascending order. An index i of a peak element when all of these three conditions are satisfied: 1. The next number on its right that's different than nums[i] doesn't present or must be smaller than nums[i] 2. The previous number on its left that's different than nums[i] doesn't present or must be smaller than nums[i] 3. There is at least one number on its left side or right side that is different from nums[i].So, if the ... Read More
312 Views
To return an Index of formatted strings specified by date format, use the DateTimeIndex.strftime() method in Pandas.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 7 and frequency as D i.e. days −datetimeindex = pd.date_range('2021-10-30 02:30:50', periods=7, tz='Australia/Adelaide', freq='2D') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Formatted −print("Format with different directives...", datetimeindex.strftime('%b. %d, %Y was a %A'))ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 7 and frequency as D i.e. days # The timezone is Australia/Adelaide datetimeindex = pd.date_range('2021-10-30 02:30:50', periods=7, tz='Australia/Adelaide', freq='2D') # display DateTimeIndex print("DateTimeIndex...", datetimeindex) # display DateTimeIndex frequency ... Read More
1K+ Views
To convert times to midnight in DateTimeIndex, use the DateTimeIndex.normalize() in Pandas.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 7 and frequency as H i.e. hours −datetimeindex = pd.date_range('2021-10-30 02:30:50', periods=7, tz='Australia/Adelaide', freq='10H') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)The time component of the date-time is converted to midnight i.e. 00:00:00 −print("Normalize (converted the time component to midnight)...", datetimeindex.normalize())ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 7 and frequency as H i.e. hours # The timezone is Australia/Adelaide datetimeindex = pd.date_range('2021-10-30 02:30:50', periods=7, tz='Australia/Adelaide', freq='10H') # display DateTimeIndex print("DateTimeIndex...", datetimeindex) ... Read More
117 Views
To return index locations of values between particular time of day in DateTimeIndex, use the DateTimeIndex.indexer_between_time() method. Set the include_start parameter to True for including the start time.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 7 and frequency as T i.e. minutes −datetimeindex = pd.date_range('2021-10-30 02:30:50', periods=7, tz='Australia/Adelaide', freq='20T') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Display index locations of values between particular time of day. The "start_time" is set '02:30:50' and "end_time" '03:20:50'. Set include_start parameter to True −print("Index locations of values between particular time of day...", datetimeindex.indexer_between_time('03:10:50', '03:50:50', include_start = True))ExampleFollowing is the code −import pandas ... Read More
321 Views
Suppose we have a list of numbers called nums. We have to find the sum of minimum of x for every sublist x in nums. If the answer is too large, then mod the result by 10^9 + 7.So, if the input is like nums = [5, 10, 20, 10, 0], then the output will be 90 because, the sublists are [[5], [10], [20], [10], [0], [5,10], [10,20], [20,10], [10,0], [5,10,20], [10,20,10], [20,10,0], [5,10,20,10], [10,20,10,0], [5,10,20,10,0]], and their minimum values are [5, 10, 20, 10, 0, 5, 10, 10, 0, 5, 10, 0, 5, 0, 0], so the sum is 90.To solve this, we will follow these steps −ans := 0s := a new listtemp_sum := 0for each index and value in nums, dowhile s and value
279 Views
To return index locations of values between particular time of day in DateTimeIndex, use the DateTimeIndex.indexer_between_time() method.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 5 and frequency as T i.e. minutes. The timezone is Australia/Adelaide −datetimeindex = pd.date_range('2021-10-30 02:30:50', periods=5, tz='Australia/Adelaide', freq='20T') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Display index locations of values between particular time of day. The "start_time" is set '02:30:50' and "end_time" '03:20:50 −print("Index locations of values between particular time of day...", datetimeindex.indexer_between_time('02:30:50', '03:20:50'))ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 5 and frequency as T i.e. minutes # ... Read More
626 Views
To return index locations of values at particular time of day in DateTimeIndex, use the DateTimeIndex.indexer_at_time() method.At first, import the required libraries −import pandas as pdCreate DatetimeIndex with period 5 and frequency as T i.e. minutes −datetimeindex = pd.date_range('2021-10-30 02:30:50', periods=5, tz='Australia/Adelaide', freq='20T') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Display index locations of values at particular time of day i.e. 03:10:50 here −print("Index locations of values at particular time of day...", datetimeindex.indexer_at_time('2021-10-30 03:10:50'))ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 5 and frequency as T i.e. minutes # The timezone is Australia/Adelaide datetimeindex = pd.date_range('2021-10-30 02:30:50', periods=5, tz='Australia/Adelaide', ... Read More
352 Views
Suppose we have a list of elements called nums, we have to check whether every sublist has at least 1 element in it that occurs exactly once in the sublist or not. We have to solve this problem in linear time.So, if the input is like nums = [5, 10, 20, 10, 0], then the output will be True, because every sublist in nums has at least one element which has occurred only once. [[5], [10], [20], [10], [0], [5, 10], [10, 20], [20, 10], [10, 0], [5, 10, 20], [10, 20, 10], [20, 10, 0], [5, 10, 20, 10], ... Read More