package day02

import java.io.File

data class Game(val number: Int, val hands: List<Hand>) {
    fun maxRed() = hands.maxOfOrNull { it.red } ?: 0
    fun maxBlue() = hands.maxOfOrNull { it.blue } ?: 0
    fun maxGreen() = hands.maxOfOrNull { it.green } ?: 0
}

data class Hand(val red: Int, val blue: Int, val green: Int)

fun main() {
    val games = gamesFromFile("src/main/resources/day02-cubes")
    println("Playable games: " + games.filter { isPlayable(it, 12, 14, 13) }.sumOf { it.number })
    println("Total power: " + games.sumOf { game -> game.hands.maxOf { it.red } * game.hands.maxOf { it.blue } * game.hands.maxOf { it.green } })
}

fun isPlayable(game: Game, reds: Int, blues: Int, greens: Int) =
    reds >= game.maxRed() && blues >= game.maxBlue() && greens >= game.maxGreen()

private fun gamesFromFile(fileName: String) = File(fileName).readLines().map { line ->
    val (number, hands) = line.split(":").map { it.trim() }
    Game(
        number = number.split(" ")[1].toInt(),
        hands = hands.split(";").map { it.trim() }.map { hand ->
            hand.split(", ").associate { cube -> cube.split(" ").run { this[1] to this[0].toInt() } }.let { cubesMap ->
                Hand(cubesMap["red"] ?: 0, cubesMap["blue"] ?: 0, cubesMap["green"] ?: 0)
            }
        }
    )
}

Compiled from "cubes.kt"
public final class day02.CubesKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/main/resources/day02-cubes
       2: invokestatic  #12                 // Method gamesFromFile:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: new           #14                 // class java/lang/StringBuilder
       9: dup
      10: invokespecial #17                 // Method java/lang/StringBuilder."<init>":()V
      13: ldc           #19                 // String Playable games:
      15: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      18: aload_0
      19: checkcast     #25                 // class java/lang/Iterable
      22: astore_1
      23: astore        14
      25: iconst_0
      26: istore_2
      27: aload_1
      28: astore_3
      29: new           #27                 // class java/util/ArrayList
      32: dup
      33: invokespecial #28                 // Method java/util/ArrayList."<init>":()V
      36: checkcast     #30                 // class java/util/Collection
      39: astore        4
      41: iconst_0
      42: istore        5
      44: aload_3
      45: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        6
      52: aload         6
      54: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          108
      62: aload         6
      64: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        7
      71: aload         7
      73: checkcast     #46                 // class day02/Game
      76: astore        8
      78: iconst_0
      79: istore        9
      81: aload         8
      83: bipush        12
      85: bipush        14
      87: bipush        13
      89: invokestatic  #50                 // Method isPlayable:(Lday02/Game;III)Z
      92: ifeq          52
      95: aload         4
      97: aload         7
      99: invokeinterface #54,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     104: pop
     105: goto          52
     108: aload         4
     110: checkcast     #56                 // class java/util/List
     113: nop
     114: aload         14
     116: swap
     117: checkcast     #25                 // class java/lang/Iterable
     120: astore_1
     121: astore        14
     123: iconst_0
     124: istore_2
     125: aload_1
     126: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     131: astore_3
     132: aload_3
     133: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     138: ifeq          178
     141: aload_3
     142: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     147: astore        4
     149: iload_2
     150: aload         4
     152: checkcast     #46                 // class day02/Game
     155: astore        5
     157: istore        15
     159: iconst_0
     160: istore        6
     162: aload         5
     164: invokevirtual #60                 // Method day02/Game.getNumber:()I
     167: istore        16
     169: iload         15
     171: iload         16
     173: iadd
     174: istore_2
     175: goto          132
     178: iload_2
     179: istore        15
     181: aload         14
     183: iload         15
     185: invokevirtual #63                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     188: invokevirtual #67                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     191: getstatic     #73                 // Field java/lang/System.out:Ljava/io/PrintStream;
     194: swap
     195: invokevirtual #79                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     198: new           #14                 // class java/lang/StringBuilder
     201: dup
     202: invokespecial #17                 // Method java/lang/StringBuilder."<init>":()V
     205: ldc           #81                 // String Total power:
     207: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     210: aload_0
     211: checkcast     #25                 // class java/lang/Iterable
     214: astore_1
     215: astore        14
     217: iconst_0
     218: istore_2
     219: aload_1
     220: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     225: astore_3
     226: aload_3
     227: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     232: ifeq          602
     235: aload_3
     236: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     241: astore        4
     243: iload_2
     244: aload         4
     246: checkcast     #46                 // class day02/Game
     249: astore        5
     251: istore        15
     253: iconst_0
     254: istore        6
     256: aload         5
     258: invokevirtual #85                 // Method day02/Game.getHands:()Ljava/util/List;
     261: checkcast     #25                 // class java/lang/Iterable
     264: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     269: astore        7
     271: aload         7
     273: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     278: ifne          289
     281: new           #87                 // class java/util/NoSuchElementException
     284: dup
     285: invokespecial #88                 // Method java/util/NoSuchElementException."<init>":()V
     288: athrow
     289: aload         7
     291: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     296: checkcast     #90                 // class day02/Hand
     299: astore        8
     301: iconst_0
     302: istore        9
     304: aload         8
     306: invokevirtual #93                 // Method day02/Hand.getRed:()I
     309: istore        8
     311: aload         7
     313: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     318: ifeq          357
     321: aload         7
     323: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     328: checkcast     #90                 // class day02/Hand
     331: astore        9
     333: iconst_0
     334: istore        10
     336: aload         9
     338: invokevirtual #93                 // Method day02/Hand.getRed:()I
     341: istore        9
     343: iload         8
     345: iload         9
     347: if_icmpge     311
     350: iload         9
     352: istore        8
     354: goto          311
     357: iload         8
     359: aload         5
     361: invokevirtual #85                 // Method day02/Game.getHands:()Ljava/util/List;
     364: checkcast     #25                 // class java/lang/Iterable
     367: astore        11
     369: istore        12
     371: aload         11
     373: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     378: astore        7
     380: aload         7
     382: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     387: ifne          398
     390: new           #87                 // class java/util/NoSuchElementException
     393: dup
     394: invokespecial #88                 // Method java/util/NoSuchElementException."<init>":()V
     397: athrow
     398: aload         7
     400: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     405: checkcast     #90                 // class day02/Hand
     408: astore        8
     410: iconst_0
     411: istore        9
     413: aload         8
     415: invokevirtual #96                 // Method day02/Hand.getBlue:()I
     418: istore        8
     420: aload         7
     422: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     427: ifeq          466
     430: aload         7
     432: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     437: checkcast     #90                 // class day02/Hand
     440: astore        9
     442: iconst_0
     443: istore        10
     445: aload         9
     447: invokevirtual #96                 // Method day02/Hand.getBlue:()I
     450: istore        9
     452: iload         8
     454: iload         9
     456: if_icmpge     420
     459: iload         9
     461: istore        8
     463: goto          420
     466: iload         8
     468: istore        13
     470: iload         12
     472: iload         13
     474: imul
     475: aload         5
     477: invokevirtual #85                 // Method day02/Game.getHands:()Ljava/util/List;
     480: checkcast     #25                 // class java/lang/Iterable
     483: astore        11
     485: istore        12
     487: aload         11
     489: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     494: astore        7
     496: aload         7
     498: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     503: ifne          514
     506: new           #87                 // class java/util/NoSuchElementException
     509: dup
     510: invokespecial #88                 // Method java/util/NoSuchElementException."<init>":()V
     513: athrow
     514: aload         7
     516: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     521: checkcast     #90                 // class day02/Hand
     524: astore        8
     526: iconst_0
     527: istore        9
     529: aload         8
     531: invokevirtual #99                 // Method day02/Hand.getGreen:()I
     534: istore        8
     536: aload         7
     538: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     543: ifeq          582
     546: aload         7
     548: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     553: checkcast     #90                 // class day02/Hand
     556: astore        9
     558: iconst_0
     559: istore        10
     561: aload         9
     563: invokevirtual #99                 // Method day02/Hand.getGreen:()I
     566: istore        9
     568: iload         8
     570: iload         9
     572: if_icmpge     536
     575: iload         9
     577: istore        8
     579: goto          536
     582: iload         8
     584: istore        13
     586: iload         12
     588: iload         13
     590: imul
     591: istore        16
     593: iload         15
     595: iload         16
     597: iadd
     598: istore_2
     599: goto          226
     602: iload_2
     603: istore        15
     605: aload         14
     607: iload         15
     609: invokevirtual #63                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     612: invokevirtual #67                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     615: getstatic     #73                 // Field java/lang/System.out:Ljava/io/PrintStream;
     618: swap
     619: invokevirtual #79                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     622: return

  public static final boolean isPlayable(day02.Game, int, int, int);
    Code:
       0: aload_0
       1: ldc           #123                // String game
       3: invokestatic  #129                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_1
       7: aload_0
       8: invokevirtual #132                // Method day02/Game.maxRed:()I
      11: if_icmplt     34
      14: iload_2
      15: aload_0
      16: invokevirtual #135                // Method day02/Game.maxBlue:()I
      19: if_icmplt     34
      22: iload_3
      23: aload_0
      24: invokevirtual #138                // Method day02/Game.maxGreen:()I
      27: if_icmplt     34
      30: iconst_1
      31: goto          35
      34: iconst_0
      35: ireturn

  private static final java.util.List<day02.Game> gamesFromFile(java.lang.String);
    Code:
       0: new           #144                // class java/io/File
       3: dup
       4: aload_0
       5: invokespecial #147                // Method java/io/File."<init>":(Ljava/lang/String;)V
       8: aconst_null
       9: iconst_1
      10: aconst_null
      11: invokestatic  #153                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      14: checkcast     #25                 // class java/lang/Iterable
      17: astore_1
      18: iconst_0
      19: istore_2
      20: aload_1
      21: astore_3
      22: new           #27                 // class java/util/ArrayList
      25: dup
      26: aload_1
      27: bipush        10
      29: invokestatic  #159                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      32: invokespecial #162                // Method java/util/ArrayList."<init>":(I)V
      35: checkcast     #30                 // class java/util/Collection
      38: astore        4
      40: iconst_0
      41: istore        5
      43: aload_3
      44: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      49: astore        6
      51: aload         6
      53: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      58: ifeq          844
      61: aload         6
      63: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      68: astore        7
      70: aload         4
      72: aload         7
      74: checkcast     #164                // class java/lang/String
      77: astore        8
      79: astore        39
      81: iconst_0
      82: istore        9
      84: aload         8
      86: checkcast     #166                // class java/lang/CharSequence
      89: iconst_1
      90: anewarray     #164                // class java/lang/String
      93: astore        10
      95: aload         10
      97: iconst_0
      98: ldc           #168                // String :
     100: aastore
     101: aload         10
     103: iconst_0
     104: iconst_0
     105: bipush        6
     107: aconst_null
     108: invokestatic  #174                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     111: checkcast     #25                 // class java/lang/Iterable
     114: astore        10
     116: iconst_0
     117: istore        11
     119: aload         10
     121: astore        12
     123: new           #27                 // class java/util/ArrayList
     126: dup
     127: aload         10
     129: bipush        10
     131: invokestatic  #159                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     134: invokespecial #162                // Method java/util/ArrayList."<init>":(I)V
     137: checkcast     #30                 // class java/util/Collection
     140: astore        13
     142: iconst_0
     143: istore        14
     145: aload         12
     147: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     152: astore        15
     154: aload         15
     156: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     161: ifeq          211
     164: aload         15
     166: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     171: astore        16
     173: aload         13
     175: aload         16
     177: checkcast     #164                // class java/lang/String
     180: astore        17
     182: astore        18
     184: iconst_0
     185: istore        19
     187: aload         17
     189: checkcast     #166                // class java/lang/CharSequence
     192: invokestatic  #178                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     195: invokevirtual #179                // Method java/lang/Object.toString:()Ljava/lang/String;
     198: nop
     199: aload         18
     201: swap
     202: invokeinterface #54,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     207: pop
     208: goto          154
     211: aload         13
     213: checkcast     #56                 // class java/util/List
     216: nop
     217: astore        20
     219: aload         20
     221: iconst_0
     222: invokeinterface #183,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     227: checkcast     #164                // class java/lang/String
     230: astore        10
     232: aload         20
     234: iconst_1
     235: invokeinterface #183,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     240: checkcast     #164                // class java/lang/String
     243: astore        11
     245: aload         10
     247: checkcast     #166                // class java/lang/CharSequence
     250: iconst_1
     251: anewarray     #164                // class java/lang/String
     254: astore        12
     256: aload         12
     258: iconst_0
     259: ldc           #185                // String
     261: aastore
     262: aload         12
     264: iconst_0
     265: iconst_0
     266: bipush        6
     268: aconst_null
     269: invokestatic  #174                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     272: iconst_1
     273: invokeinterface #183,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     278: checkcast     #164                // class java/lang/String
     281: invokestatic  #191                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     284: aload         11
     286: checkcast     #166                // class java/lang/CharSequence
     289: iconst_1
     290: anewarray     #164                // class java/lang/String
     293: astore        12
     295: aload         12
     297: iconst_0
     298: ldc           #193                // String ;
     300: aastore
     301: aload         12
     303: iconst_0
     304: iconst_0
     305: bipush        6
     307: aconst_null
     308: invokestatic  #174                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     311: checkcast     #25                 // class java/lang/Iterable
     314: astore        12
     316: istore        21
     318: iconst_0
     319: istore        13
     321: aload         12
     323: astore        14
     325: new           #27                 // class java/util/ArrayList
     328: dup
     329: aload         12
     331: bipush        10
     333: invokestatic  #159                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     336: invokespecial #162                // Method java/util/ArrayList."<init>":(I)V
     339: checkcast     #30                 // class java/util/Collection
     342: astore        15
     344: iconst_0
     345: istore        16
     347: aload         14
     349: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     354: astore        17
     356: aload         17
     358: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     363: ifeq          413
     366: aload         17
     368: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     373: astore        19
     375: aload         15
     377: aload         19
     379: checkcast     #164                // class java/lang/String
     382: astore        22
     384: astore        23
     386: iconst_0
     387: istore        24
     389: aload         22
     391: checkcast     #166                // class java/lang/CharSequence
     394: invokestatic  #178                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     397: invokevirtual #179                // Method java/lang/Object.toString:()Ljava/lang/String;
     400: nop
     401: aload         23
     403: swap
     404: invokeinterface #54,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     409: pop
     410: goto          356
     413: aload         15
     415: checkcast     #56                 // class java/util/List
     418: nop
     419: astore        23
     421: iload         21
     423: aload         23
     425: checkcast     #25                 // class java/lang/Iterable
     428: astore        12
     430: istore        21
     432: iconst_0
     433: istore        13
     435: aload         12
     437: astore        14
     439: new           #27                 // class java/util/ArrayList
     442: dup
     443: aload         12
     445: bipush        10
     447: invokestatic  #159                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     450: invokespecial #162                // Method java/util/ArrayList."<init>":(I)V
     453: checkcast     #30                 // class java/util/Collection
     456: astore        15
     458: iconst_0
     459: istore        16
     461: aload         14
     463: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     468: astore        17
     470: aload         17
     472: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     477: ifeq          804
     480: aload         17
     482: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     487: astore        19
     489: aload         15
     491: aload         19
     493: checkcast     #164                // class java/lang/String
     496: astore        22
     498: astore        23
     500: iconst_0
     501: istore        24
     503: aload         22
     505: checkcast     #166                // class java/lang/CharSequence
     508: iconst_1
     509: anewarray     #164                // class java/lang/String
     512: astore        25
     514: aload         25
     516: iconst_0
     517: ldc           #195                // String ,
     519: aastore
     520: aload         25
     522: iconst_0
     523: iconst_0
     524: bipush        6
     526: aconst_null
     527: invokestatic  #174                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     530: checkcast     #25                 // class java/lang/Iterable
     533: astore        25
     535: iconst_0
     536: istore        26
     538: aload         25
     540: bipush        10
     542: invokestatic  #159                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     545: invokestatic  #201                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     548: bipush        16
     550: invokestatic  #207                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     553: istore        27
     555: aload         25
     557: astore        28
     559: new           #209                // class java/util/LinkedHashMap
     562: dup
     563: iload         27
     565: invokespecial #210                // Method java/util/LinkedHashMap."<init>":(I)V
     568: checkcast     #212                // class java/util/Map
     571: astore        29
     573: iconst_0
     574: istore        30
     576: aload         28
     578: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     583: astore        31
     585: aload         31
     587: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     592: ifeq          703
     595: aload         31
     597: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     602: astore        32
     604: aload         29
     606: astore        33
     608: aload         32
     610: checkcast     #164                // class java/lang/String
     613: astore        34
     615: iconst_0
     616: istore        35
     618: aload         34
     620: checkcast     #166                // class java/lang/CharSequence
     623: iconst_1
     624: anewarray     #164                // class java/lang/String
     627: astore        36
     629: aload         36
     631: iconst_0
     632: ldc           #185                // String
     634: aastore
     635: aload         36
     637: iconst_0
     638: iconst_0
     639: bipush        6
     641: aconst_null
     642: invokestatic  #174                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     645: astore        37
     647: iconst_0
     648: istore        38
     650: aload         37
     652: iconst_1
     653: invokeinterface #183,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     658: aload         37
     660: iconst_0
     661: invokeinterface #183,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     666: checkcast     #164                // class java/lang/String
     669: invokestatic  #191                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     672: invokestatic  #216                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     675: invokestatic  #222                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     678: nop
     679: nop
     680: astore        34
     682: aload         33
     684: aload         34
     686: invokevirtual #227                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     689: aload         34
     691: invokevirtual #230                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     694: invokeinterface #234,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     699: pop
     700: goto          585
     703: aload         29
     705: nop
     706: astore        26
     708: iconst_0
     709: istore        27
     711: new           #90                 // class day02/Hand
     714: dup
     715: aload         26
     717: ldc           #236                // String red
     719: invokeinterface #239,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     724: checkcast     #187                // class java/lang/Integer
     727: dup
     728: ifnull        737
     731: invokevirtual #242                // Method java/lang/Integer.intValue:()I
     734: goto          739
     737: pop
     738: iconst_0
     739: aload         26
     741: ldc           #244                // String blue
     743: invokeinterface #239,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     748: checkcast     #187                // class java/lang/Integer
     751: dup
     752: ifnull        761
     755: invokevirtual #242                // Method java/lang/Integer.intValue:()I
     758: goto          763
     761: pop
     762: iconst_0
     763: aload         26
     765: ldc           #246                // String green
     767: invokeinterface #239,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     772: checkcast     #187                // class java/lang/Integer
     775: dup
     776: ifnull        785
     779: invokevirtual #242                // Method java/lang/Integer.intValue:()I
     782: goto          787
     785: pop
     786: iconst_0
     787: invokespecial #249                // Method day02/Hand."<init>":(III)V
     790: nop
     791: nop
     792: aload         23
     794: swap
     795: invokeinterface #54,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     800: pop
     801: goto          470
     804: aload         15
     806: checkcast     #56                 // class java/util/List
     809: nop
     810: astore        23
     812: iload         21
     814: aload         23
     816: astore        40
     818: istore        41
     820: new           #46                 // class day02/Game
     823: dup
     824: iload         41
     826: aload         40
     828: invokespecial #252                // Method day02/Game."<init>":(ILjava/util/List;)V
     831: nop
     832: aload         39
     834: swap
     835: invokeinterface #54,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     840: pop
     841: goto          51
     844: aload         4
     846: checkcast     #56                 // class java/util/List
     849: nop
     850: areturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #282                // Method main:()V
       3: return
}


package com.mouredev.weeklychallenge2022

/*
 * Reto #39
 * TOP ALGORITMOS: QUICK SORT
 * Fecha publicación enunciado: 27/09/22
 * Fecha publicación resolución: 03/10/22
 * Dificultad: MEDIA
 *
 * Enunciado: Implementa uno de los algoritmos de ordenación más famosos: el "Quick Sort",
 * creado por <NAME>.
 * - Entender el funcionamiento de los algoritmos más utilizados de la historia nos ayuda a
 *   mejorar nuestro conocimiento sobre ingeniería de software. Dedícale tiempo a entenderlo,
 *   no únicamente a copiar su implementación.
 * - Esta es una nueva serie de retos llamada "TOP ALGORITMOS", donde trabajaremos y entenderemos
 *   los más famosos de la historia.
 *
 * Información adicional:
 * - Usa el canal de nuestro Discord (https://mouredev.com/discord) "🔁reto-semanal"
 *   para preguntas, dudas o prestar ayuda a la comunidad.
 * - Tienes toda la información sobre los retos semanales en
 *   https://retosdeprogramacion.com/semanales2022.
 *
 */

// Basado en https://www.genbeta.com/desarrollo/implementando-el-algoritmo-quicksort

fun main() {
    val sortedArray = quicksort(arrayOf(3, 5, 1, 8, 9, 0))
    sortedArray.forEach {
        println(it)
    }
}

private fun quicksort(array: Array<Int>): Array<Int> {
    return if (array.isEmpty()) array else quicksort(array, 0, array.size - 1)
}

private fun quicksort(array: Array<Int>, first: Int, last: Int): Array<Int> {

    var i = first
    var j = last
    var array = array
    val pivot = (array[i] + array[j]) / 2

    while (i < j) {

        while (array[i] < pivot) {
            i += 1
        }

        while (array[j] > pivot) {
            j -= 1
        }

        if (i <= j) {

            val x = array[j]

            array[j] = array[i]
            array[i] = x

            i += 1
            j -= 1
        }
    }

    if (first < j) {
        array = quicksort(array, first, j)
    }

    if (last > i) {
        array = quicksort(array, i, last)
    }

    return array
}

Compiled from "Challenge39.kt"
public final class com.mouredev.weeklychallenge2022.Challenge39Kt {
  public static final void main();
    Code:
       0: bipush        6
       2: anewarray     #8                  // class java/lang/Integer
       5: astore_1
       6: aload_1
       7: iconst_0
       8: iconst_3
       9: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      12: aastore
      13: aload_1
      14: iconst_1
      15: iconst_5
      16: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      19: aastore
      20: aload_1
      21: iconst_2
      22: iconst_1
      23: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      26: aastore
      27: aload_1
      28: iconst_3
      29: bipush        8
      31: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      34: aastore
      35: aload_1
      36: iconst_4
      37: bipush        9
      39: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      42: aastore
      43: aload_1
      44: iconst_5
      45: iconst_0
      46: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      49: aastore
      50: aload_1
      51: invokestatic  #16                 // Method quicksort:([Ljava/lang/Integer;)[Ljava/lang/Integer;
      54: astore_0
      55: aload_0
      56: astore_1
      57: iconst_0
      58: istore_2
      59: iconst_0
      60: istore_3
      61: aload_1
      62: arraylength
      63: istore        4
      65: iload_3
      66: iload         4
      68: if_icmpge     105
      71: aload_1
      72: iload_3
      73: aaload
      74: astore        5
      76: aload         5
      78: checkcast     #18                 // class java/lang/Number
      81: invokevirtual #22                 // Method java/lang/Number.intValue:()I
      84: istore        6
      86: iconst_0
      87: istore        7
      89: getstatic     #28                 // Field java/lang/System.out:Ljava/io/PrintStream;
      92: iload         6
      94: invokevirtual #34                 // Method java/io/PrintStream.println:(I)V
      97: nop
      98: nop
      99: iinc          3, 1
     102: goto          65
     105: nop
     106: return

  private static final java.lang.Integer[] quicksort(java.lang.Integer[]);
    Code:
       0: aload_0
       1: arraylength
       2: ifne          9
       5: iconst_1
       6: goto          10
       9: iconst_0
      10: ifeq          17
      13: aload_0
      14: goto          26
      17: aload_0
      18: iconst_0
      19: aload_0
      20: arraylength
      21: iconst_1
      22: isub
      23: invokestatic  #48                 // Method quicksort:([Ljava/lang/Integer;II)[Ljava/lang/Integer;
      26: areturn

  private static final java.lang.Integer[] quicksort(java.lang.Integer[], int, int);
    Code:
       0: iload_1
       1: istore_3
       2: iload_2
       3: istore        4
       5: aload_0
       6: astore        5
       8: aload         5
      10: iload_3
      11: aaload
      12: invokevirtual #50                 // Method java/lang/Integer.intValue:()I
      15: aload         5
      17: iload         4
      19: aaload
      20: invokevirtual #50                 // Method java/lang/Integer.intValue:()I
      23: iadd
      24: iconst_2
      25: idiv
      26: istore        6
      28: iload_3
      29: iload         4
      31: if_icmpge     114
      34: aload         5
      36: iload_3
      37: aaload
      38: invokevirtual #50                 // Method java/lang/Integer.intValue:()I
      41: iload         6
      43: if_icmpge     52
      46: iinc          3, 1
      49: goto          34
      52: aload         5
      54: iload         4
      56: aaload
      57: invokevirtual #50                 // Method java/lang/Integer.intValue:()I
      60: iload         6
      62: if_icmple     71
      65: iinc          4, -1
      68: goto          52
      71: iload_3
      72: iload         4
      74: if_icmpgt     28
      77: aload         5
      79: iload         4
      81: aaload
      82: invokevirtual #50                 // Method java/lang/Integer.intValue:()I
      85: istore        7
      87: aload         5
      89: iload         4
      91: aload         5
      93: iload_3
      94: aaload
      95: aastore
      96: aload         5
      98: iload_3
      99: iload         7
     101: invokestatic  #12                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     104: aastore
     105: iinc          3, 1
     108: iinc          4, -1
     111: goto          28
     114: iload_1
     115: iload         4
     117: if_icmpge     130
     120: aload         5
     122: iload_1
     123: iload         4
     125: invokestatic  #48                 // Method quicksort:([Ljava/lang/Integer;II)[Ljava/lang/Integer;
     128: astore        5
     130: iload_2
     131: iload_3
     132: if_icmple     144
     135: aload         5
     137: iload_3
     138: iload_2
     139: invokestatic  #48                 // Method quicksort:([Ljava/lang/Integer;II)[Ljava/lang/Integer;
     142: astore        5
     144: aload         5
     146: areturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #59                 // Method main:()V
       3: return
}


package com.leetcode.top_interview_questions.easy.merge

fun main() {
    println("Test case 1:")
    val arr1 = intArrayOf(1, 2, 3, 0, 0, 0)
    val arr2 = intArrayOf(2, 5, 6)
    println(Solution().merge(arr1, 3, arr2, 3)) // [1,2,2,3,5,6]
    println(arr1.toList())
    println()

    println("Test case 2:")
    val arr3 = intArrayOf(1)
    val arr4 = intArrayOf()
    println(Solution().merge(arr3, 1, arr4, 0)) // [1]
    println(arr3.toList())
    println()

    println("Test case 3:")
    val arr5 = intArrayOf(0)
    val arr6 = intArrayOf(1)
    println(Solution().merge(arr5, 0, arr6, 1)) // [1]
    println(arr5.toList())
    println()

    println("Test case 4:")
    val arr7 = intArrayOf(2, 0)
    val arr8 = intArrayOf(1)
    println(Solution().merge(arr7, 1, arr8, 1)) // [1, 2]
    println(arr7.toList())
    println()

    println("Test case 5:")
    val arr9 = intArrayOf(4, 0, 0, 0, 0, 0)
    val arr10 = intArrayOf(1, 2, 3, 5, 6)
    println(Solution().merge(arr9, 1, arr10, 5)) // [1,2,3,4,5,6]
    println(arr9.toList())
    println()
}

class Solution {
    fun merge(nums1: IntArray, m: Int, nums2: IntArray, n: Int) {
        var p1 = m - 1
        var p2 = n - 1
        var i = m + n - 1
        while (p2 >= 0) {
            if (p1 >= 0 && nums1[p1] > nums2[p2]) {
                nums1[i--] = nums1[p1--]
            } else {
                nums1[i--] = nums2[p2--]

            }

        }
    }
}

Compiled from "Main.kt"
public final class com.leetcode.top_interview_questions.easy.merge.MainKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Test case 1:
       2: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
       5: swap
       6: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       9: bipush        6
      11: newarray       int
      13: astore_1
      14: aload_1
      15: iconst_0
      16: iconst_1
      17: iastore
      18: aload_1
      19: iconst_1
      20: iconst_2
      21: iastore
      22: aload_1
      23: iconst_2
      24: iconst_3
      25: iastore
      26: aload_1
      27: iconst_3
      28: iconst_0
      29: iastore
      30: aload_1
      31: iconst_4
      32: iconst_0
      33: iastore
      34: aload_1
      35: iconst_5
      36: iconst_0
      37: iastore
      38: aload_1
      39: astore_0
      40: iconst_3
      41: newarray       int
      43: astore_2
      44: aload_2
      45: iconst_0
      46: iconst_2
      47: iastore
      48: aload_2
      49: iconst_1
      50: iconst_5
      51: iastore
      52: aload_2
      53: iconst_2
      54: bipush        6
      56: iastore
      57: aload_2
      58: astore_1
      59: new           #22                 // class com/leetcode/top_interview_questions/easy/merge/Solution
      62: dup
      63: invokespecial #25                 // Method com/leetcode/top_interview_questions/easy/merge/Solution."<init>":()V
      66: aload_0
      67: iconst_3
      68: aload_1
      69: iconst_3
      70: invokevirtual #29                 // Method com/leetcode/top_interview_questions/easy/merge/Solution.merge:([II[II)V
      73: getstatic     #35                 // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      76: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      79: swap
      80: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      83: aload_0
      84: invokestatic  #41                 // Method kotlin/collections/ArraysKt.toList:([I)Ljava/util/List;
      87: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      90: swap
      91: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      94: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      97: invokevirtual #43                 // Method java/io/PrintStream.println:()V
     100: ldc           #45                 // String Test case 2:
     102: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     105: swap
     106: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     109: iconst_1
     110: newarray       int
     112: astore_3
     113: aload_3
     114: iconst_0
     115: iconst_1
     116: iastore
     117: aload_3
     118: astore_2
     119: iconst_0
     120: newarray       int
     122: astore_3
     123: new           #22                 // class com/leetcode/top_interview_questions/easy/merge/Solution
     126: dup
     127: invokespecial #25                 // Method com/leetcode/top_interview_questions/easy/merge/Solution."<init>":()V
     130: aload_2
     131: iconst_1
     132: aload_3
     133: iconst_0
     134: invokevirtual #29                 // Method com/leetcode/top_interview_questions/easy/merge/Solution.merge:([II[II)V
     137: getstatic     #35                 // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     140: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     143: swap
     144: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     147: aload_2
     148: invokestatic  #41                 // Method kotlin/collections/ArraysKt.toList:([I)Ljava/util/List;
     151: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     154: swap
     155: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     158: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     161: invokevirtual #43                 // Method java/io/PrintStream.println:()V
     164: ldc           #47                 // String Test case 3:
     166: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     169: swap
     170: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     173: iconst_1
     174: newarray       int
     176: astore        5
     178: aload         5
     180: iconst_0
     181: iconst_0
     182: iastore
     183: aload         5
     185: astore        4
     187: iconst_1
     188: newarray       int
     190: astore        6
     192: aload         6
     194: iconst_0
     195: iconst_1
     196: iastore
     197: aload         6
     199: astore        5
     201: new           #22                 // class com/leetcode/top_interview_questions/easy/merge/Solution
     204: dup
     205: invokespecial #25                 // Method com/leetcode/top_interview_questions/easy/merge/Solution."<init>":()V
     208: aload         4
     210: iconst_0
     211: aload         5
     213: iconst_1
     214: invokevirtual #29                 // Method com/leetcode/top_interview_questions/easy/merge/Solution.merge:([II[II)V
     217: getstatic     #35                 // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     220: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     223: swap
     224: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     227: aload         4
     229: invokestatic  #41                 // Method kotlin/collections/ArraysKt.toList:([I)Ljava/util/List;
     232: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     235: swap
     236: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     239: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     242: invokevirtual #43                 // Method java/io/PrintStream.println:()V
     245: ldc           #49                 // String Test case 4:
     247: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     250: swap
     251: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     254: iconst_2
     255: newarray       int
     257: astore        7
     259: aload         7
     261: iconst_0
     262: iconst_2
     263: iastore
     264: aload         7
     266: iconst_1
     267: iconst_0
     268: iastore
     269: aload         7
     271: astore        6
     273: iconst_1
     274: newarray       int
     276: astore        8
     278: aload         8
     280: iconst_0
     281: iconst_1
     282: iastore
     283: aload         8
     285: astore        7
     287: new           #22                 // class com/leetcode/top_interview_questions/easy/merge/Solution
     290: dup
     291: invokespecial #25                 // Method com/leetcode/top_interview_questions/easy/merge/Solution."<init>":()V
     294: aload         6
     296: iconst_1
     297: aload         7
     299: iconst_1
     300: invokevirtual #29                 // Method com/leetcode/top_interview_questions/easy/merge/Solution.merge:([II[II)V
     303: getstatic     #35                 // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     306: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     309: swap
     310: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     313: aload         6
     315: invokestatic  #41                 // Method kotlin/collections/ArraysKt.toList:([I)Ljava/util/List;
     318: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     321: swap
     322: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     325: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     328: invokevirtual #43                 // Method java/io/PrintStream.println:()V
     331: ldc           #51                 // String Test case 5:
     333: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     336: swap
     337: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     340: bipush        6
     342: newarray       int
     344: astore        9
     346: aload         9
     348: iconst_0
     349: iconst_4
     350: iastore
     351: aload         9
     353: iconst_1
     354: iconst_0
     355: iastore
     356: aload         9
     358: iconst_2
     359: iconst_0
     360: iastore
     361: aload         9
     363: iconst_3
     364: iconst_0
     365: iastore
     366: aload         9
     368: iconst_4
     369: iconst_0
     370: iastore
     371: aload         9
     373: iconst_5
     374: iconst_0
     375: iastore
     376: aload         9
     378: astore        8
     380: iconst_5
     381: newarray       int
     383: astore        10
     385: aload         10
     387: iconst_0
     388: iconst_1
     389: iastore
     390: aload         10
     392: iconst_1
     393: iconst_2
     394: iastore
     395: aload         10
     397: iconst_2
     398: iconst_3
     399: iastore
     400: aload         10
     402: iconst_3
     403: iconst_5
     404: iastore
     405: aload         10
     407: iconst_4
     408: bipush        6
     410: iastore
     411: aload         10
     413: astore        9
     415: new           #22                 // class com/leetcode/top_interview_questions/easy/merge/Solution
     418: dup
     419: invokespecial #25                 // Method com/leetcode/top_interview_questions/easy/merge/Solution."<init>":()V
     422: aload         8
     424: iconst_1
     425: aload         9
     427: iconst_5
     428: invokevirtual #29                 // Method com/leetcode/top_interview_questions/easy/merge/Solution.merge:([II[II)V
     431: getstatic     #35                 // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     434: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     437: swap
     438: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     441: aload         8
     443: invokestatic  #41                 // Method kotlin/collections/ArraysKt.toList:([I)Ljava/util/List;
     446: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     449: swap
     450: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     453: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     456: invokevirtual #43                 // Method java/io/PrintStream.println:()V
     459: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #65                 // Method main:()V
       3: return
}


package com.leetcode.top100LikedQuestions.easy.maxim_depth_of_binary_tree

fun main() {
    println("Test case 1:")
    val t1 = TreeNode(1)

    run {
        val leftFirstLeaf = TreeNode(3)
        val rightFirstLeaf = TreeNode(2)

        val leftSecondLeaf = TreeNode(5)
        val rightSecondLeaf = null

        //set nodes
        t1.left = leftFirstLeaf
        t1.right = rightFirstLeaf

        leftFirstLeaf.left = leftSecondLeaf
        leftFirstLeaf.right = rightSecondLeaf
    }

    println(Solution().maxDepth(t1))
    println()

    println("Test case 2:")
    println(Solution().maxDepth(null))
    println()
}

/**
 * Example:
 * var ti = TreeNode(5)
 * var v = ti.`val`
 * Definition for a binary tree node.
 * class TreeNode(var `val`: Int) {
 *     var left: TreeNode? = null
 *     var right: TreeNode? = null
 * }
 */
class Solution {
    fun maxDepth(root: TreeNode?, currentDepth: Int = 1): Int {
        if (root == null) return 0
        if (root.left == null && root.right == null) return currentDepth

        val leftSide = if (root.left != null) maxDepth(root.left, currentDepth + 1) else 0
        val rightSide = if (root.right != null) maxDepth(root.right, currentDepth + 1) else 0

        return Math.max(leftSide, rightSide)
    }
}

class TreeNode(var `val`: Int) {
    var left: TreeNode? = null
    var right: TreeNode? = null
}

Compiled from "Main.kt"
public final class com.leetcode.top100LikedQuestions.easy.maxim_depth_of_binary_tree.MainKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Test case 1:
       2: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
       5: swap
       6: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       9: new           #22                 // class com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode
      12: dup
      13: iconst_1
      14: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode."<init>":(I)V
      17: astore_0
      18: iconst_0
      19: istore_1
      20: new           #22                 // class com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode
      23: dup
      24: iconst_3
      25: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode."<init>":(I)V
      28: astore_2
      29: new           #22                 // class com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode
      32: dup
      33: iconst_2
      34: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode."<init>":(I)V
      37: astore_3
      38: new           #22                 // class com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode
      41: dup
      42: iconst_5
      43: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode."<init>":(I)V
      46: astore        4
      48: aconst_null
      49: astore        5
      51: aload_0
      52: aload_2
      53: invokevirtual #30                 // Method com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode.setLeft:(Lcom/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode;)V
      56: aload_0
      57: aload_3
      58: invokevirtual #33                 // Method com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode.setRight:(Lcom/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode;)V
      61: aload_2
      62: aload         4
      64: invokevirtual #30                 // Method com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode.setLeft:(Lcom/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode;)V
      67: aload_2
      68: aload         5
      70: invokevirtual #33                 // Method com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode.setRight:(Lcom/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode;)V
      73: nop
      74: nop
      75: new           #35                 // class com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/Solution
      78: dup
      79: invokespecial #37                 // Method com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/Solution."<init>":()V
      82: aload_0
      83: iconst_0
      84: iconst_2
      85: aconst_null
      86: invokestatic  #41                 // Method com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/Solution.maxDepth$default:(Lcom/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/Solution;Lcom/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode;IILjava/lang/Object;)I
      89: istore_1
      90: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      93: iload_1
      94: invokevirtual #43                 // Method java/io/PrintStream.println:(I)V
      97: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     100: invokevirtual #45                 // Method java/io/PrintStream.println:()V
     103: ldc           #47                 // String Test case 2:
     105: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     108: swap
     109: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     112: new           #35                 // class com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/Solution
     115: dup
     116: invokespecial #37                 // Method com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/Solution."<init>":()V
     119: aconst_null
     120: iconst_0
     121: iconst_2
     122: aconst_null
     123: invokestatic  #41                 // Method com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/Solution.maxDepth$default:(Lcom/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/Solution;Lcom/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/TreeNode;IILjava/lang/Object;)I
     126: istore_1
     127: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     130: iload_1
     131: invokevirtual #43                 // Method java/io/PrintStream.println:(I)V
     134: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     137: invokevirtual #45                 // Method java/io/PrintStream.println:()V
     140: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #59                 // Method main:()V
       3: return
}


package com.leetcode.top100LikedQuestions.easy.symetric_binary_tree

fun main() {
    println("Test case 1:")
    val t1 = TreeNode(1)
    t1.left = TreeNode(2)
    t1.right = TreeNode(2)

    t1.left!!.left = TreeNode(3)
    t1.left!!.right = TreeNode(4)

    t1.right!!.left = TreeNode(4)
    t1.right!!.right = TreeNode(3)
    println(Solution().isSymmetric(t1))

    println("Test case 2:")
    val t2 = TreeNode(1)
    t2.left = TreeNode(2)
    t2.right = TreeNode(2)

    t2.left!!.right = TreeNode(3)

    t2.right!!.right = TreeNode(3)
    println(Solution().isSymmetric(t2))

    println()
}

/**
 * Example:
 * var ti = TreeNode(5)
 * var v = ti.`val`
 * Definition for a binary tree node.
 * class TreeNode(var `val`: Int) {
 *     var left: TreeNode? = null
 *     var right: TreeNode? = null
 * }
 */
class Solution {
    fun isSymmetric(root: TreeNode?): Boolean {
        return isSymmetric(root?.left, root?.right)
    }

    fun isSymmetric(left: TreeNode?, right: TreeNode?): Boolean {
        if (left != null && right == null) return false
        if (left == null && right != null) return false
        if (left == null && right == null) return true
        if (left?.`val` != null && left.`val` != right?.`val`) {
            return false
        }

        return isSymmetric(left?.left, right?.right) && isSymmetric(left?.right, right?.left)
    }
}

class TreeNode(var `val`: Int) {
    var left: TreeNode? = null
    var right: TreeNode? = null
}

Compiled from "Main.kt"
public final class com.leetcode.top100LikedQuestions.easy.symetric_binary_tree.MainKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Test case 1:
       2: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
       5: swap
       6: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       9: new           #22                 // class com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode
      12: dup
      13: iconst_1
      14: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode."<init>":(I)V
      17: astore_0
      18: aload_0
      19: new           #22                 // class com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode
      22: dup
      23: iconst_2
      24: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode."<init>":(I)V
      27: invokevirtual #30                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode.setLeft:(Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;)V
      30: aload_0
      31: new           #22                 // class com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode
      34: dup
      35: iconst_2
      36: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode."<init>":(I)V
      39: invokevirtual #33                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode.setRight:(Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;)V
      42: aload_0
      43: invokevirtual #37                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode.getLeft:()Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;
      46: dup
      47: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      50: new           #22                 // class com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode
      53: dup
      54: iconst_3
      55: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode."<init>":(I)V
      58: invokevirtual #30                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode.setLeft:(Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;)V
      61: aload_0
      62: invokevirtual #37                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode.getLeft:()Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;
      65: dup
      66: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      69: new           #22                 // class com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode
      72: dup
      73: iconst_4
      74: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode."<init>":(I)V
      77: invokevirtual #33                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode.setRight:(Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;)V
      80: aload_0
      81: invokevirtual #45                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode.getRight:()Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;
      84: dup
      85: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      88: new           #22                 // class com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode
      91: dup
      92: iconst_4
      93: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode."<init>":(I)V
      96: invokevirtual #30                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode.setLeft:(Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;)V
      99: aload_0
     100: invokevirtual #45                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode.getRight:()Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;
     103: dup
     104: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     107: new           #22                 // class com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode
     110: dup
     111: iconst_3
     112: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode."<init>":(I)V
     115: invokevirtual #33                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode.setRight:(Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;)V
     118: new           #47                 // class com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/Solution
     121: dup
     122: invokespecial #49                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/Solution."<init>":()V
     125: aload_0
     126: invokevirtual #53                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/Solution.isSymmetric:(Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;)Z
     129: istore_1
     130: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     133: iload_1
     134: invokevirtual #56                 // Method java/io/PrintStream.println:(Z)V
     137: ldc           #58                 // String Test case 2:
     139: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     142: swap
     143: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     146: new           #22                 // class com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode
     149: dup
     150: iconst_1
     151: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode."<init>":(I)V
     154: astore_1
     155: aload_1
     156: new           #22                 // class com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode
     159: dup
     160: iconst_2
     161: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode."<init>":(I)V
     164: invokevirtual #30                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode.setLeft:(Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;)V
     167: aload_1
     168: new           #22                 // class com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode
     171: dup
     172: iconst_2
     173: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode."<init>":(I)V
     176: invokevirtual #33                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode.setRight:(Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;)V
     179: aload_1
     180: invokevirtual #37                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode.getLeft:()Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;
     183: dup
     184: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     187: new           #22                 // class com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode
     190: dup
     191: iconst_3
     192: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode."<init>":(I)V
     195: invokevirtual #33                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode.setRight:(Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;)V
     198: aload_1
     199: invokevirtual #45                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode.getRight:()Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;
     202: dup
     203: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     206: new           #22                 // class com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode
     209: dup
     210: iconst_3
     211: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode."<init>":(I)V
     214: invokevirtual #33                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode.setRight:(Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;)V
     217: new           #47                 // class com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/Solution
     220: dup
     221: invokespecial #49                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/Solution."<init>":()V
     224: aload_1
     225: invokevirtual #53                 // Method com/leetcode/top100LikedQuestions/easy/symetric_binary_tree/Solution.isSymmetric:(Lcom/leetcode/top100LikedQuestions/easy/symetric_binary_tree/TreeNode;)Z
     228: istore_2
     229: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     232: iload_2
     233: invokevirtual #56                 // Method java/io/PrintStream.println:(Z)V
     236: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     239: invokevirtual #60                 // Method java/io/PrintStream.println:()V
     242: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #66                 // Method main:()V
       3: return
}


package com.leetcode.top100LikedQuestions.easy.mergind_two_binaries_tree

/**
 * Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.

You need to merge them into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of new tree.

Example 1:

Input:
Tree 1                     Tree 2
1                         2
/ \                       / \
3   2                     1   3
/                           \   \
5                             4   7
Output:
Merged tree:
3
/ \
4   5
/ \   \
5   4   7

Note: The merging process must start from the root nodes of both trees.

 */
fun main() {
    println("Test case 1:")
    //t1
    val t1 = TreeNode(1)

    run {
        val leftFirstLeaf = TreeNode(3)
        val rightFirstLeaf = TreeNode(2)

        val leftSecondLeaf = TreeNode(5)
        val rightSecondLeaf = null

        //set nodes
        t1.left = leftFirstLeaf
        t1.right = rightFirstLeaf

        leftFirstLeaf.left = leftSecondLeaf
        leftFirstLeaf.right = rightSecondLeaf
    }

    //t2
    val t2 = TreeNode(2)

    run {
        val leftFirstLeaf = TreeNode(1)
        val rightFirstLeaf = TreeNode(3)

        val leftSecondLeaf = null
        val rightSecondLeaf = TreeNode(4)

        val leftSecondLeaf2 = null
        val rightSecondLeaf2 = TreeNode(7)

        //set nodes
        t1.left = leftFirstLeaf
        t1.right = rightFirstLeaf

        leftFirstLeaf.left = leftSecondLeaf
        leftFirstLeaf.right = rightSecondLeaf

        rightFirstLeaf.left = leftSecondLeaf2
        rightFirstLeaf.right = rightSecondLeaf2
    }

    println(Solution().mergeTrees(t1, t2))

    println()
}

/**
 * Example:
 * var ti = TreeNode(5)
 * var v = ti.`val`
 * Definition for a binary tree node.
 * class TreeNode(var `val`: Int) {
 *     var left: TreeNode? = null
 *     var right: TreeNode? = null
 * }
 */
class Solution {
    fun mergeTrees(t1: TreeNode?, t2: TreeNode?): TreeNode? {
        if (t1 == null) return t2
        if (t2 == null) return t1

        t1.`val` += t2.`val`

        t1.left = mergeTrees(t1.left, t2.left)
        t1.right = mergeTrees(t1.right, t2.right)

        return t1
    }
}

class TreeNode(var `val`: Int) {
    var left: TreeNode? = null
    var right: TreeNode? = null
}

Compiled from "Main.kt"
public final class com.leetcode.top100LikedQuestions.easy.mergind_two_binaries_tree.MainKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Test case 1:
       2: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
       5: swap
       6: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       9: new           #22                 // class com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode
      12: dup
      13: iconst_1
      14: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode."<init>":(I)V
      17: astore_0
      18: iconst_0
      19: istore_1
      20: new           #22                 // class com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode
      23: dup
      24: iconst_3
      25: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode."<init>":(I)V
      28: astore_2
      29: new           #22                 // class com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode
      32: dup
      33: iconst_2
      34: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode."<init>":(I)V
      37: astore_3
      38: new           #22                 // class com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode
      41: dup
      42: iconst_5
      43: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode."<init>":(I)V
      46: astore        4
      48: aconst_null
      49: astore        5
      51: aload_0
      52: aload_2
      53: invokevirtual #30                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode.setLeft:(Lcom/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode;)V
      56: aload_0
      57: aload_3
      58: invokevirtual #33                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode.setRight:(Lcom/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode;)V
      61: aload_2
      62: aload         4
      64: invokevirtual #30                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode.setLeft:(Lcom/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode;)V
      67: aload_2
      68: aload         5
      70: invokevirtual #33                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode.setRight:(Lcom/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode;)V
      73: nop
      74: nop
      75: new           #22                 // class com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode
      78: dup
      79: iconst_2
      80: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode."<init>":(I)V
      83: astore_1
      84: iconst_0
      85: istore_2
      86: new           #22                 // class com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode
      89: dup
      90: iconst_1
      91: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode."<init>":(I)V
      94: astore_3
      95: new           #22                 // class com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode
      98: dup
      99: iconst_3
     100: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode."<init>":(I)V
     103: astore        4
     105: aconst_null
     106: astore        5
     108: new           #22                 // class com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode
     111: dup
     112: iconst_4
     113: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode."<init>":(I)V
     116: astore        6
     118: aconst_null
     119: astore        7
     121: new           #22                 // class com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode
     124: dup
     125: bipush        7
     127: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode."<init>":(I)V
     130: astore        8
     132: aload_0
     133: aload_3
     134: invokevirtual #30                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode.setLeft:(Lcom/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode;)V
     137: aload_0
     138: aload         4
     140: invokevirtual #33                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode.setRight:(Lcom/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode;)V
     143: aload_3
     144: aload         5
     146: invokevirtual #30                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode.setLeft:(Lcom/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode;)V
     149: aload_3
     150: aload         6
     152: invokevirtual #33                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode.setRight:(Lcom/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode;)V
     155: aload         4
     157: aload         7
     159: invokevirtual #30                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode.setLeft:(Lcom/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode;)V
     162: aload         4
     164: aload         8
     166: invokevirtual #33                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode.setRight:(Lcom/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode;)V
     169: nop
     170: nop
     171: new           #35                 // class com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/Solution
     174: dup
     175: invokespecial #37                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/Solution."<init>":()V
     178: aload_0
     179: aload_1
     180: invokevirtual #41                 // Method com/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/Solution.mergeTrees:(Lcom/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode;Lcom/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode;)Lcom/leetcode/top100LikedQuestions/easy/mergind_two_binaries_tree/TreeNode;
     183: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     186: swap
     187: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     190: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     193: invokevirtual #43                 // Method java/io/PrintStream.println:()V
     196: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #59                 // Method main:()V
       3: return
}


package com.leetcode.top100LikedQuestions.medium.add_two_numbers

fun main() {
    println("Test case 1:")
    val ll1 = ListNode(2, ListNode(4, ListNode(3, null)))
    val ll2 = ListNode(5, ListNode(6, ListNode(4, null)))
    println(Solution().addTwoNumbers(ll1, ll2)) //[7,0,8]
    println()

    println("Test case 2:")
    val ll12 = ListNode(9, ListNode(9, ListNode(9, null)))
    val ll22 = ListNode(9, ListNode(9, null))
    println(Solution().addTwoNumbers(ll12, ll22)) //[8, 9, 0, 1]
    println()

    println("Test case 3:")
    val ll13 = ListNode(5, null)
    val ll23 = ListNode(5, null)
    println(Solution().addTwoNumbers(ll13, ll23)) //[0, 1]
    println()

}

class Solution {
    fun addTwoNumbers(l1: ListNode?, l2: ListNode?): ListNode? {
        if (l1 == null || l2 == null) return null

        var newLinkedList: ListNode? = null
        var currL1 = l1
        var currL2 = l2
        var rest = 0
        while (currL1 != null || currL2 != null) {
            val f1 = if (currL1?.`val` == null) 0 else currL1.`val`
            val f2 = if (currL2?.`val` == null) 0 else currL2.`val`
            var sum = f1 + f2
            if (sum > 9) {
                sum = sum - 10 + rest
                rest = 1
            } else {
                if (sum == 10) {
                    sum = 0
                    rest = 1
                } else {
                    sum = sum + rest
                    if (sum > 9) {
                        sum = sum - 10
                        rest = 1
                    } else {
                        rest = 0
                    }
                }
            }

            if (newLinkedList == null) {
                newLinkedList = ListNode(sum, null)

                if (currL1?.next == null && currL2?.next == null && rest != 0) {
                    newLinkedList.next = ListNode(rest, null)
                }

            } else {
                var lastElement = newLinkedList
                while (lastElement?.next != null) {
                    lastElement = lastElement.next
                }
                lastElement?.next = ListNode(sum, null)

                if (currL1?.next == null && currL2?.next == null && rest != 0) {
                    lastElement?.next?.next = ListNode(rest, null)
                }
            }

            currL1 = currL1?.next
            currL2 = currL2?.next
        }

        return newLinkedList
    }
}

data class ListNode(var `val`: Int, var next: ListNode? = null)

Compiled from "Main.kt"
public final class com.leetcode.top100LikedQuestions.medium.add_two_numbers.MainKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Test case 1:
       2: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
       5: swap
       6: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       9: new           #22                 // class com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode
      12: dup
      13: iconst_2
      14: new           #22                 // class com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode
      17: dup
      18: iconst_4
      19: new           #22                 // class com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode
      22: dup
      23: iconst_3
      24: aconst_null
      25: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode."<init>":(ILcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;)V
      28: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode."<init>":(ILcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;)V
      31: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode."<init>":(ILcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;)V
      34: astore_0
      35: new           #22                 // class com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode
      38: dup
      39: iconst_5
      40: new           #22                 // class com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode
      43: dup
      44: bipush        6
      46: new           #22                 // class com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode
      49: dup
      50: iconst_4
      51: aconst_null
      52: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode."<init>":(ILcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;)V
      55: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode."<init>":(ILcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;)V
      58: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode."<init>":(ILcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;)V
      61: astore_1
      62: new           #28                 // class com/leetcode/top100LikedQuestions/medium/add_two_numbers/Solution
      65: dup
      66: invokespecial #30                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/Solution."<init>":()V
      69: aload_0
      70: aload_1
      71: invokevirtual #34                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/Solution.addTwoNumbers:(Lcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;Lcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;)Lcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;
      74: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      77: swap
      78: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      81: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      84: invokevirtual #36                 // Method java/io/PrintStream.println:()V
      87: ldc           #38                 // String Test case 2:
      89: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      92: swap
      93: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      96: new           #22                 // class com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode
      99: dup
     100: bipush        9
     102: new           #22                 // class com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode
     105: dup
     106: bipush        9
     108: new           #22                 // class com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode
     111: dup
     112: bipush        9
     114: aconst_null
     115: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode."<init>":(ILcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;)V
     118: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode."<init>":(ILcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;)V
     121: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode."<init>":(ILcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;)V
     124: astore_2
     125: new           #22                 // class com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode
     128: dup
     129: bipush        9
     131: new           #22                 // class com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode
     134: dup
     135: bipush        9
     137: aconst_null
     138: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode."<init>":(ILcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;)V
     141: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode."<init>":(ILcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;)V
     144: astore_3
     145: new           #28                 // class com/leetcode/top100LikedQuestions/medium/add_two_numbers/Solution
     148: dup
     149: invokespecial #30                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/Solution."<init>":()V
     152: aload_2
     153: aload_3
     154: invokevirtual #34                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/Solution.addTwoNumbers:(Lcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;Lcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;)Lcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;
     157: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     160: swap
     161: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     164: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     167: invokevirtual #36                 // Method java/io/PrintStream.println:()V
     170: ldc           #40                 // String Test case 3:
     172: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     175: swap
     176: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     179: new           #22                 // class com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode
     182: dup
     183: iconst_5
     184: aconst_null
     185: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode."<init>":(ILcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;)V
     188: astore        4
     190: new           #22                 // class com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode
     193: dup
     194: iconst_5
     195: aconst_null
     196: invokespecial #26                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode."<init>":(ILcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;)V
     199: astore        5
     201: new           #28                 // class com/leetcode/top100LikedQuestions/medium/add_two_numbers/Solution
     204: dup
     205: invokespecial #30                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/Solution."<init>":()V
     208: aload         4
     210: aload         5
     212: invokevirtual #34                 // Method com/leetcode/top100LikedQuestions/medium/add_two_numbers/Solution.addTwoNumbers:(Lcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;Lcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;)Lcom/leetcode/top100LikedQuestions/medium/add_two_numbers/ListNode;
     215: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     218: swap
     219: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     222: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     225: invokevirtual #36                 // Method java/io/PrintStream.println:()V
     228: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #50                 // Method main:()V
       3: return
}


package com.leetcode.random_problems.easy.maximum_product_in_array

fun main() {
    println("Test case 1:")
//    Explanation: We can choose indices 1 and 3 for the first pair (6, 7) and indices 2 and 4 for the second pair (2, 4).
//    The product difference is (6 * 7) - (2 * 4) = 34.
    println(Solution().maxProductDifference(intArrayOf(5, 6, 2, 7, 4))) // 34
    println()

    println("Test case 2:")
//    Explanation: We can choose indices 3 and 6 for the first pair (9, 8) and indices 1 and 5 for the second pair (2, 4).
//    The product difference is (9 * 8) - (2 * 4) = 64.
    println(Solution().maxProductDifference(intArrayOf(4, 2, 5, 9, 7, 4, 8))) // 64
    println()

}

class Solution {
    fun maxProductDifference(nums: IntArray): Int {
        val pairs = nums.sortedDescending().zipWithNext()
        val maxProduct = pairs.first().first * pairs.first().second
        val minProduct = pairs.last().first * pairs.last().second

        return maxProduct - minProduct
    }
}

Compiled from "Main.kt"
public final class com.leetcode.random_problems.easy.maximum_product_in_array.MainKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Test case 1:
       2: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
       5: swap
       6: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       9: new           #22                 // class com/leetcode/random_problems/easy/maximum_product_in_array/Solution
      12: dup
      13: invokespecial #25                 // Method com/leetcode/random_problems/easy/maximum_product_in_array/Solution."<init>":()V
      16: iconst_5
      17: newarray       int
      19: astore_0
      20: aload_0
      21: iconst_0
      22: iconst_5
      23: iastore
      24: aload_0
      25: iconst_1
      26: bipush        6
      28: iastore
      29: aload_0
      30: iconst_2
      31: iconst_2
      32: iastore
      33: aload_0
      34: iconst_3
      35: bipush        7
      37: iastore
      38: aload_0
      39: iconst_4
      40: iconst_4
      41: iastore
      42: aload_0
      43: invokevirtual #29                 // Method com/leetcode/random_problems/easy/maximum_product_in_array/Solution.maxProductDifference:([I)I
      46: istore_0
      47: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      50: iload_0
      51: invokevirtual #32                 // Method java/io/PrintStream.println:(I)V
      54: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      57: invokevirtual #34                 // Method java/io/PrintStream.println:()V
      60: ldc           #36                 // String Test case 2:
      62: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      65: swap
      66: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      69: new           #22                 // class com/leetcode/random_problems/easy/maximum_product_in_array/Solution
      72: dup
      73: invokespecial #25                 // Method com/leetcode/random_problems/easy/maximum_product_in_array/Solution."<init>":()V
      76: bipush        7
      78: newarray       int
      80: astore_0
      81: aload_0
      82: iconst_0
      83: iconst_4
      84: iastore
      85: aload_0
      86: iconst_1
      87: iconst_2
      88: iastore
      89: aload_0
      90: iconst_2
      91: iconst_5
      92: iastore
      93: aload_0
      94: iconst_3
      95: bipush        9
      97: iastore
      98: aload_0
      99: iconst_4
     100: bipush        7
     102: iastore
     103: aload_0
     104: iconst_5
     105: iconst_4
     106: iastore
     107: aload_0
     108: bipush        6
     110: bipush        8
     112: iastore
     113: aload_0
     114: invokevirtual #29                 // Method com/leetcode/random_problems/easy/maximum_product_in_array/Solution.maxProductDifference:([I)I
     117: istore_0
     118: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     121: iload_0
     122: invokevirtual #32                 // Method java/io/PrintStream.println:(I)V
     125: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     128: invokevirtual #34                 // Method java/io/PrintStream.println:()V
     131: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #39                 // Method main:()V
       3: return
}