Show newer

@Surasanji as soon as you send the check I will have a version with your name on it.. This one looks really easy though, the trick is making it pythonic. I can almost imagine a regex solution.

Wow, lots of followers today!

If you are interested in any of my coding challenges they should all be tagged with :

If you put that in your search and scroll to to bottom you will see my original proposal. Here is a link with the explanation of where my head is at. The ones I post that I call freebies, are from a subscription to Job Interview problems, and they should be a little tricky, but are usually rated as easy, medium or hard.

qoto.org/@Absinthe/10280565958

Today's Freebie. It's marked as easy.

This problem was asked by Amazon.

Run-length encoding is a fast and simple method of encoding strings. The basic idea is to represent repeated successive characters as a single count and character. For example, the string "AAAABBBCCDAA" would be encoded as "4A3B2C1D2A".

Implement run-length encoding and decoding. You can assume the string to be encoded have no digits and consists solely of alphabetic characters. You can assume the string to be decoded is valid.

while ps -p 5637 >/dev/null; do sleep 5;done; echo "done"| mail -s foo 8125551234@vtext.com # Notification when pid 5637 done

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
Show older
Qoto Mastodon

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