Solved LeetCode program · 945 of 1,000
#1311 · Get Watched Videos by Your Friends
Original English source
Keep a shared names as an empty list of text. Keep a shared counts as an empty list of whole numbers. Keep a shared wantedtext as empty text. Keep a shared total of 0. Keep a shared winner of 0. Keep a shared starts as an empty list of whole numbers. Keep a shared edges as an empty list of whole numbers. Keep a shared degrees as an empty list of whole numbers. Keep a shared videos as an empty list of text. Keep a shared videostarts as an empty list of whole numbers. Keep a shared videosizes as an empty list of whole numbers. Keep a shared depths as an empty list of whole numbers. Keep a shared visited as an empty list of whole numbers. Keep a shared queue as an empty list of whole numbers. Keep a shared tail of 0. Place 0 into starts. Place 2 into starts. Place 4 into starts. Place 6 into starts. Place 1 into edges. Place 2 into edges. Place 0 into edges. Place 3 into edges. Place 0 into edges. Place 3 into edges. Place 1 into edges. Place 2 into edges. Place 2 into degrees. Place 2 into degrees. Place 2 into degrees. Place 2 into degrees. Place "A" into videos. Place "B" into videos. Place "C" into videos. Place "B" into videos. Place "C" into videos. Place "D" into videos. Place 0 into videostarts. Place 2 into videostarts. Place 3 into videostarts. Place 5 into videostarts. Place 2 into videosizes. Place 1 into videosizes. Place 2 into videosizes. Place 1 into videosizes.
For every person from 0 to 3.
Place 0 into depths. Place 0 into visited. Place 0 into queue. Place 0 into queue.
To register. Set found to -1. For every spot from 0 to total minus 1, if item spot of names matches wantedtext, set found to spot. If found is less than 0, Place wantedtext into names, Place 1 into counts, add 1 to total, otherwise set item found of counts to item found of counts plus 1.
To offer from node (a whole number) with offset (a whole number). The base is item node of videostarts. The video is item (base plus offset) of videos. Set wantedtext to video. Register.
To gather from node (a whole number). For every offset from 0 to item node of videosizes minus 1, Offer from node with offset.
To reach from node (a whole number) with offset (a whole number). The base is item node of starts. The target is item (base plus offset) of edges. If item node of depths is less than 1 and item target of visited is 0, Set item target of visited to 1, Set item target of depths to item node of depths plus 1, Set item tail of queue to target, Add 1 to tail.
To expand from node (a whole number). For every offset from 0 to item node of degrees minus 1, Reach from node with offset.
To work from node (a whole number). If item node of depths is 1, Gather from node, otherwise Expand from node.
The head is 0. Set tail to 1. Set item 0 of queue to 0. Set item 0 of visited to 1.
Repeat while head is less than tail.
The node is item head of queue. Add 1 to head. Work from node.
To compare from other (a whole number) with best (a whole number). The othername is item other of names. The bestname is item best of names. If item other of counts is less than item best of counts or item other of counts is item best of counts and character 0 of othername is less than character 0 of bestname, set winner to other.
To settle from spot (a whole number). Set winner to spot. For every other from spot plus 1 to total minus 1, Compare from other with winner. The best is winner. The holdname is item spot of names. The holdcount is item spot of counts. Set item spot of names to item best of names. Set item spot of counts to item best of counts. Set item best of names to holdname. Set item best of counts to holdcount.
For every spot from 0 to total minus 2, Settle from spot. For each name in names, show name.
Expected stdout
B C