# Is this valid for this SE site?

I am new to this SE and don't know if this fits theme of this website. That is why first posting in meta site. Feel free to suggest some other SE if applicable. Sorry for the long post. But this much info is needed to explain !

### Background:

I am student and working in one science institute. Our university has bunch of transport services which runs on daily bases based on pre-existing timings.

For example :

On Mon to Sat: 07:00, 11:00, 16:00 ...
On Sundays: 09:30, 12:30, 21:00 ...


There can be any number of trips per day or even each day can have different trips.

Whenever I run this program, it should give me back next trip when we have input in following form

monday = { "07:00", "11:00", "16:00",...}
sunday = { "09:30", "12:30", "21:00", ...}


For example :

run() #On Monday 09:00
>>Output : 11:00
run() #On Sunday 13:30
>>Output: 21:00


Initially I thought it is very easy job. But unfortunately, my university added trips post midnight , For example

monday =  { "07:00", "11:00", "16:00",..., "01:30"}
sunday = { "09:30", "12:30", "21:00", ..., "02:00"}


Here trip mentioned in Monday list "01:30" is actually on Tuesday. This broke my existing algorithm. So currently I am using following algorithm,

Step1: Distribute each input into 3 parts : first trip, trips after that and trips after midnight e.g

monday =  { "07:00", "11:00", "16:00",..., "01:30"}
monday_first = {"07:00"}
monday_rest = {"11:00", "16:00"...}
monday_post_midnight = {"01:30"}


Step2 : Combine lists from yesterday's midnight, first trip and rest of the trips

e.g.

new_monday_trip = sunday_midnight + monday_first + monday_rest
new_monday_trip = {"02:00", "07:00","11:00", "16:00"...}


Step3: Check current time and get next trip from list. If it is present then show it to user or get first item from next day.

I was wondering if is there any better way.

Note: Each input will be always in chronological order

### Example Input Set

monday to saturday =  { "07:00", "11:00", "12:30", "16:00", "21:00", "00:00", "01:30"}
sunday = { "09:30", "12:30", "21:00", "00:30","01:30", "02:00"}

• Welcome to PPCG! If this is a programming question about how to do something or why your (well-researched) code doesn't work, it belongs on stackoverflow.com. If you have code that works but you want to see if it's a good program, it belongs on codereview.stackexchange.com. If this is a programming challenge for us to do, then this is the place to go! You can post challenges here first, so that the community can review the challenge before your post it.
– user42649
Commented Mar 1, 2017 at 13:45