Show newer

Here's a Freebie, it is marked as "Easy"

This problem was asked by Facebook.

Given a string of round, curly, and square open and closing brackets, return whether the brackets are balanced (well-formed).

For example, given the string "([])[]({})", you should return true.

Given the string "([)]" or "((()", you should return false.

@mikelga I was thinking about this earlier.

So you take your first lecture, and assign it to a room

Then you rake your next one, and if it is an overlap you put it in a new room, otherwise put it in the same room.

Then take the next one, if it only overlaps one of the ones in the first room, then whichever one was earlier goes in the room and the one that gets displaced then goes it gets tested against the next room. and so on down the line. When you are out of lectures, count up the rooms.

@mikelga You can look at the lectures as having a StartTime and an EndTime and so if a lecture has a StartTime that is greater than the StartTime of another and less than the EndTime of that same one then they overlap. If one's start time is greater than another's EndTime then they don't overlap.

The number of rooms you would need depends on the overlaps. If you have no overlaps then you only need one room. Each overlap may require an additional room. If one overlaps multiple other rooms, then once you have accounted for it having a room, you start the rule over for the rest of the rooms. For an example:

a = 1 to 5
b = 4 to 6
c = 7 to 9
If you provide a room for b you can server a and b with a single extra room.

If you provide a room for b then A and C will still overlap.
a = 1 to 5
b = 2 to 7
c = 4 to 9

Does that help clear it up?


Here's a freebie!

This problem was asked by Snapchat.

Given an array of time intervals (start, end) for classroom lectures (possibly overlapping), find the minimum number of rooms required.

For example, given [(30, 75), (0, 50), (60, 150)], you should return 2.

Here is one I have been playing with.

Factorials and Fibonacci numbers are traditionally used as examples of recursive functions.

Let's see them done without recursion with reasonable timing.

I apologize for not coming up with a new one this week, but I will post a few freebies.

I discovered discord, and I spent too much free time helping 8th graders do their home work :) Or so it would appear.

Octave solution 

@khird I haven't attacked this one yet. But from what I can see it is essentially the same problem as the non-adjacent sums problem. When I look at it, I will come up with some test cases

@khird @freemo It is pretty well cleaned up now. and I fleshed out the list a little to make it iterable and printable and stuff. Take a peek!

Please suggest one, just remember to include the hash tag

@khird

I spoke with a colleague over lunch today and we got into solutions for finding cyclical linked lists. So taking from the discussion we had, I wanted to see if I could implement it. Unfortunately, none of these except the bad list reversal one are my own design. The two pointer solution was suggested in a similar problem on LeetCode. So basically, I wanted to implement it and see it work. I just had a few minutes between work and the gym, so I wanted to get something up. Definitely not grade A code.

Ultimately the two pointer solution is likely what they were looking for. Certainly can use some code cleanup. At least some error checking. :)

@khird take another look. I removed the reversing one, and replaced it with one that destroys the next pointers, and and another that modifies the vals. Along with the 2 pointer one, these should all work. I think it needs some cleanup though. Let me know what you see.

@khird yes, you are absolutely right. I heard another solution today that may also work that I want to try. And it will require that the nodes are more correct like you are doing them. As I have it with your changes the second reverse should scramble it. But if you only reverse one of them you could go through a while until the n.next.next == n. I may get away with a destructive version as well. Check later.

Okay, so my solution didn't meet the O(n+m) complexity. But Iound the correct algorithm, and both are in place and the code is updated. @freemo this was kind of interesting, reminds me of an old card trick I used to do.

Show thread

@twee@patch.cx @mngrif I just use a cheap lavolere from Amazon. I can look it up. Or sometimes the built-in one on the LG phone that I was using. I bought a dedicated camera and haven't made a vid since.

@billstclair@kiwifarms.cc @billstclair@gab.com

youtube.com/watch?v=O2iGMYeZb9

Now it is, but it was designed by IMI and from '82 to '05 it was made by IMI and from '05-09 was a joint thing between IMI and MR.. And since 2009 it is made by MR. And GD made it between 95-98.

en.wikipedia.org/wiki/Desert_E

@billstclair I think the specific lyric is "...And a Desert Eagle that's one great big ol' pistol
I mean .50 caliber made by badass Hebrews" only thing I know by IMI that is mentioned in a song :)

@billstclair ever listen to the song Chocta Bingo by Ray Wylie Hubbard? There's a line in it about the Desert Eagle.

Show older
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.