Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,156,242 members, 7,829,442 topics. Date: Thursday, 16 May 2024 at 07:02 AM |
Nairaland Forum / Science/Technology / Programming / Python Coding Challenge (664 Views)
A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? / Turing Live Coding Challenge / A 30 Day Coding Challenge (Python) For BEGINNERS (2) (3) (4)
(1) (Reply)
Python Coding Challenge by akinademayowa(m): 5:56pm On Jan 31, 2022 |
Any python programmer here? I have a challenge for you. You can help with a solution pls. You can also use any language of your choice apart from python.. You're given a list of time intervals during which students at a school need a laptop. These time intervals are represented by pairs of integers [start, end], where 0 <= start < end. However, start and end don't represent real times; therefore, they may be greater than 24. No two students can use a laptop at the same time, but immediately after a student is done using a laptop, another student can use that same laptop. For example, if one student rents a laptop during the time interval [0, 2], another student can rent the same laptop during any time interval starting with 2. Write a function that returns the minimum number of laptops that the school needs to rent such that all students will always have access to a laptop when they need one. laptopRentals(times) Parameters times: Array (of Array (of Integers)) - A 2D array containing the times the student would require a laptop. Return Value Integer - Minimum number of laptops the school needs to rent. Examples times Return Value [[0,2],[1,4],[4,6],[0,4],[7,8],[9,11],[3,10]] 3 [[0,4],[2,3],[2,3],[2,3]] 4 [[1,5],[5,6],[6,7],[7,9]] 1 # Code.... def rents(times): pass times = [[0,2],[1,4],[4,6],[0,4],[7,8],[9,11],[3,10]] |
Re: Python Coding Challenge by ichidodo: 7:53pm On Feb 01, 2022 |
minimum number of laptops to fit into the minimum time intervals allotted for laptop rentals in one day will be the same number of laptops the school is obliged to rent irrespective of the population size of the school........ |
Re: Python Coding Challenge by Altairx440: 10:17am On Feb 08, 2022 |
akinademayowa: we can translate the logic into something like this: given a 2d array of times, find how many times it will take to empty the array following the sequential order described. e.g: [[2,3], [3,5], [6, 10]] = 1 times i.e 2,3,3,6,10, e.g2: [[0,1], [0,3], [2,3], [4,6]] = 2 times. we could write a non-formal algorithm as: set count = 0 repeat: set head = times.pop(0) // first element of a list/ array set found_items = [] // create emptylist for eacb elem after head to last elem: if head[1] == elem[0] or head[1] == elem[0] - 1, then add elem to found end end remove all elements in times thats in list count += 1 untill times is empty. output count another potential solution would be sorting times first and using a for loop. it's not code, so there might be bugs but it'll definetely work. where did you get the question from? |
(1) (Reply)
New Forum Is Out Now, Take A Review On It / Chatgpt Understands Pidgin English / Smart Startups Series - The Advantage
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 97 |