>(without sorting). iterate through all the rest of them and keep track of the smallest time past the current time that has been seen so far
Angel Torres
>people like OP are the next generation of programmers
Liam Smith
I think of it as job security.
Brandon Morales
thanks, that's what i was thinking as well. what would the big O of this approach be? is sorting with something like bubble sort better? its worst-case performance is O(n^2)
Matthew Myers
This. Lmao
Aaron Morales
Why you want me to do your homework OP?
Benjamin Sanders
It's a single pass that only compares the current smallest to current index, you should be able to figure it out
Andrew Roberts
O(n)?
Nicholas Gutierrez
That's basically a min(array) algorithm with a custom min(a,b) function. At least don't post dijkstra when you're posting these stupid questions.
Benjamin Martin
Yes It's O(n) worst case
Michael Gomez
Kids these days aren't getting into programming for the passion, they're getting into it because of the money and because Obama said it was cool to do so
Elijah Adams
grep then subtract and compare
Michael Baker
Sup Forums is that way --->
Wyatt Robinson
...
Joseph Fisher
he's right desu
Ryder Turner
temp = first date in list iterate over all dates, if date < temp && date > given then temp = date if temp < given (it's the first in list which was also smaller) then return None else return temp
Luke Jones
Convert it all to unix time, then compare. But sort it, don't be a faggot.
Nathaniel Nguyen
Too many retarded and over complicated answers ITT
just take your dates, run a loop through them that deletes all - and spaces and : characters
you'll be left with 201802081023 for example
proceed to convert them all to integers and sort like you do normally.
Ethan Johnson
>SORRRRRRT
Luke Lopez
Is it DD-MM or MM-DD? You can't tell with your examples, you should include a day after the 12th.
Christian Bailey
???
you don't know how to sort an array of integers?
Cameron Jones
>given one of them, is there an algorithm for finding the one that follows chronologically (without sorting).
Connor Cruz
Can it have dates less than a minute apart, causing duplicate dates? If I find a 9:31 can I stop searching?
Ian Phillips
You dare post dijkstra next to this retarded post? Shame on you OP.
Asher Brooks
Cant you ever read OP, also you shit answere is stupid and slow
Luis Williams
fucking retard i don't care if this is bait or not
Eli Brooks
translate all into (nano)seconds from epoch >without sorting find the smallest greater value by iteration then
Nicholas Rogers
>get to the h:mm instead of hh:mm >kernel panic
Ian Richardson
This is your only option, OP, O(n) in any case. But why wouldn't you want that shit sorted? Is it, like, milliards of entries? Because if it's not - you're retarded, and should use something like bucket/radix sort - this problem is literally a textbook example for it
> bubble sort are for fucking real?
I seriously hope nobody ever runs your code in production. May god have mercy on the soul of whoever dares
Lincoln Evans
If there's a unique smallest greater date (see ) then an O(1) best case would exist
Sebastian Russell
right, you can optimize it that way if you wish, but it's one comparison more for every check.
Gavin Wood
Point is, OP seem unable to supply exact requirements even after been asked. I suspect this might be an homework assignment.
Jackson Murphy
Ok, for each date, add a label for year, month, day and time. Now subtract the year label with each date. Now you will only consider the dates whose subtraction equal to 0 , because all of them will be the same year. Then you do the same for months and days. This way at the end the code will only consider the dates whose year, month and day are the same. Then every hour will be pased to 24 hours. You subtract them in a way that if the number is negative you add a hourdate1beforedatex, if it positive hourdate1afterdatex, that way it easy to compare them (example date1beforedate2, date2beforedate3 ten date1beforedate3). Then the code go back and take another day, if this day its the same than date1, then pass to the next (also add a code for when there is a sigle year, month or day). I am too lazy to keep thinking how would you compare then the days, months and years, but I guess that the same method for hours would work.
Zachary Wright
No. FUCKING NO. Don't do this retarded thing. convert to epoch time with build-in method/function. The answer is right after the date to epoch convertion. > I am too lazy to keep thinking Rise your iq to three digits then you can post.
Brody Brooks
With MY method you will had less dates to work with. Good luck iteratig over thousand and thousand of dates.
Joshua Martin
lel no. one pass to put labels : Ω(n) with n the size of the list putting label : O(1) iterating throught dates is Ω(1) but O(n) in the worst case. If you have the whole set of date stored in cache you won't have that many cache-missed in the second pass. it's O(2n) ~ O(n) and you have unknow duration on the second pass, it's retarded when you can do everything in one pass. getting epoch time from the system is heavy as you have to change context to get the hardware time but converting date to epoch is trivial and can be done by highschoolers.
usually you sort dates when you store them so you can quick sort (usually some enhanced merge sort which take advantage of caches sizes).
Juan Reyes
MM-DD
Matthew Murphy
>because of the money and because Obama said it was cool to do so perfect, they are doing not only for being greedy retards but communists too. What a wonderful world we live in.
Aiden Jackson
I did it because I liked computers. Now that I have my CS degree I realise that I hate computers
Jack Johnson
>dijkstra.jpg >this retardation kys
Carson Garcia
take a substring of each integer. convert it to a const integer data type. Proceed to compare each value against its counterpart.
Landon Jenkins
let smallest equal infinity
for date in dates do let timestamp equal date converted to unix timestamp if timestamp is less than smallest then assign timestamp to smallest end end
I have never coded in my life, but thanks for the explanation.
Dylan Watson
The rule of thumb is that it's always YYY:MM:DD. It makes sense when you try and sort them by descending, etc. They'll actually be in the correct order chronologically
Austin Hernandez
YYYY-MM-DD **
Blake Gray
GNU sort.
Carson Lewis
...
Nathaniel Green
STRING SEARCH
Justin Perry
>It's O(n) worst case It's redundant to say worst case. O(n) implies worst case.
Caleb Lee
Hey Ethan, great moves.
Henry Hill
var result = datelist.orderby(x => x)
or something
Jaxon Cruz
What implies best and average case?
Samuel Price
omega for the best case, "average case" is an interesting concept.