Sinisterly
Legends Reconstruct the queue - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Coding (https://sinister.ly/Forum-Coding--71)
+--- Thread: Legends Reconstruct the queue (/Thread-Legends-Reconstruct-the-queue)



Reconstruct the queue - Nil - 11-02-2017

I don't leetcode often so maybe these types of puzzles just aren't ringing my bell, but I have no clue after 10 minutes of thought what exactly is meant by reconstructing the queue. Any thoughts?

https://leetcode.com/problems/queue-reconstruction-by-height/description/

Edit: Came back to it later and figured it out https://sinister.ly/Thread-Legends-Reconstruct-the-queue?pid=784087#pid784087
Comment if you have any questions


RE: Reconstruct the queue - OversouL - 11-02-2017

After reading the problem. I think it meant you should order them by height. Highest being the last or vice versa. Sounds fun, but I don't have time. :L I probably forgot how to code anyway. xD


RE: Reconstruct the queue - Nil - 11-02-2017

(11-02-2017, 02:33 AM)OversouL Wrote: After reading the problem. I think it meant you should order them by height. Highest being the last or vice versa. Sounds fun, but I don't have time. :L I probably forgot how to code anyway.  xD

Not quite. If you look at the example output you can see that the height isn't the determining factor for the order.


RE: Reconstruct the queue - OversouL - 11-02-2017

(11-02-2017, 03:13 AM)God Wrote:
(11-02-2017, 02:33 AM)OversouL Wrote: After reading the problem. I think it meant you should order them by height. Highest being the last or vice versa. Sounds fun, but I don't have time. :L I probably forgot how to code anyway.  xD

Not quite. If you look at the example output you can see that the height isn't the determining factor for the order.

Oh totally ignored it. XD

Perhaps the number of people in front takes priority. If number of people in front is 0 then it should be listed first. If there are more inputs with k = 0 then they are rearranged by height. But also the number of persons in front must be satisfied first. I dunno, it's kinda hard to explain.

I think I could apply the algorithms I learned from my data structures class, but I already forgot. XD


RE: Reconstruct the queue - Nil - 11-02-2017

Well just took a break and looked at it again and realized it's fairly simple now. Implementing it isn't so simple but the gist of it is to view the front of the line as the first element. And then it's just arranging them in an order for where each item to the right's k value holds true for it's position.