CP-1.012 Java Tutorial - Map.Entry and var

Published: 26 September 2021
on channel: Daniel Sutantyo
650
5

Problem: Sort (https://open.kattis.com/problems/sort)

I discuss yet another way to traverse through a map: using Map.Entry, which we'll also use to 'sort' the map. I'm also starting to use the var keyword which makes life easier.

I realise that I didn't fully explain how the sort works, but it's actually very simple. For descending order, given a and b, we want to return a positive number if a is less than b, and a negative number otherwise (or 0 if a == b). You can read up on Java compareTo.

Note that my compareTo implementation will have a.compareTo(b) returning a positive number if a is greater than b BUT this is because by default sorting is done in ascending order. We have to flip it for this problem.

Video Sections:
0:00 - Problem description
2:33 - Start of solution - LinkedHashMap
3:27 - var keyword
5:34 - Using Map.Entry
8:34 - Porting the map into an ArrayList
11:12 - Printing the output
13:42 - Summary

Please note that all views and opinions expressed in this video are my own and does not reflect that of Kattis or any other person/organisation mentioned in the video.


On this page of the site you can watch the video online CP-1.012 Java Tutorial - Map.Entry and var with a duration of hours minute second in good quality, which was uploaded by the user Daniel Sutantyo 26 September 2021, share the link with friends and acquaintances, this video has already been watched 650 times on youtube and it was liked by 5 viewers. Enjoy your viewing!