package twentytwenty

import java.io.File
import java.nio.file.Paths

class DayOne {
    private var inputList: ArrayList<Int> = ArrayList<Int>()

    internal var partOneAnswer: Int = 0

    internal var partTwoAnswer: Int = 0

    fun loadInputFile(filename: String) {
        val path = Paths.get("").toAbsolutePath().toString()
        File("$path/$filename").forEachLine {
            inputList.add(it.toInt())
        }
    }

    private fun quickSort(input: ArrayList<Int>): ArrayList<Int> {
        if (input.count() < 2) {
            return input
        }
        val pivot = input[input.count()/2]
        val equal = input.filter { it == pivot } as ArrayList<Int>
        val less = input.filter { it < pivot } as ArrayList<Int>
        val greater = input.filter { it > pivot } as ArrayList<Int>
        return (quickSort(less) + equal + quickSort(greater)) as ArrayList<Int>
    }

    fun solvePartOne() {
        if (inputList.count()==0) { loadInputFile("src/data/DayOneInput.txt") }
        var filtered = inputList.filter { it < 2020 }
        var sorted = quickSort(filtered as ArrayList<Int>)
        loop@ for (lowVal in sorted) {
            for (highVal in sorted.reversed()) {
                if (lowVal + highVal == 2020) {
                    partOneAnswer = lowVal * highVal
                    break@loop
                }
            }
        }
    }

    fun solvePartTwo() {
        if (inputList.count()==0) { loadInputFile("src/data/DayOneInput.txt") }
        var filtered = inputList.filter { it < 2020}
        var sorted = quickSort(filtered as ArrayList<Int>)

        loop@ for(first in sorted) {
            for(second in sorted.filter { it != first}) {
                for(third in sorted.filter  { it != first && it != second }) {
                    if (first + second + third == 2020) {
                        partTwoAnswer = first * second * third
                        break@loop
                    }
                }
            }
        }
    }
}

Compiled from "DayOne.kt"
public final class twentytwenty.DayOne {
  private java.util.ArrayList<java.lang.Integer> inputList;

  private int partOneAnswer;

  private int partTwoAnswer;

  public twentytwenty.DayOne();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: new           #10                 // class java/util/ArrayList
       8: dup
       9: invokespecial #11                 // Method java/util/ArrayList."<init>":()V
      12: putfield      #15                 // Field inputList:Ljava/util/ArrayList;
      15: return

  public final int getPartOneAnswer$main();
    Code:
       0: aload_0
       1: getfield      #23                 // Field partOneAnswer:I
       4: ireturn

  public final void setPartOneAnswer$main(int);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #23                 // Field partOneAnswer:I
       5: return

  public final int getPartTwoAnswer$main();
    Code:
       0: aload_0
       1: getfield      #30                 // Field partTwoAnswer:I
       4: ireturn

  public final void setPartTwoAnswer$main(int);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #30                 // Field partTwoAnswer:I
       5: return

  public final void loadInputFile(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #36                 // String filename
       3: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #44                 // String
       8: iconst_0
       9: anewarray     #46                 // class java/lang/String
      12: invokestatic  #52                 // Method java/nio/file/Paths.get:(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;
      15: invokeinterface #58,  1           // InterfaceMethod java/nio/file/Path.toAbsolutePath:()Ljava/nio/file/Path;
      20: invokevirtual #62                 // Method java/lang/Object.toString:()Ljava/lang/String;
      23: astore_2
      24: new           #64                 // class java/io/File
      27: dup
      28: new           #66                 // class java/lang/StringBuilder
      31: dup
      32: invokespecial #67                 // Method java/lang/StringBuilder."<init>":()V
      35: aload_2
      36: invokevirtual #71                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      39: bipush        47
      41: invokevirtual #74                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      44: aload_1
      45: invokevirtual #71                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      48: invokevirtual #75                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: invokespecial #77                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      54: aconst_null
      55: aload_0
      56: invokedynamic #97,  0             // InvokeDynamic #0:invoke:(Ltwentytwenty/DayOne;)Lkotlin/jvm/functions/Function1;
      61: iconst_1
      62: aconst_null
      63: invokestatic  #103                // Method kotlin/io/FilesKt.forEachLine$default:(Ljava/io/File;Ljava/nio/charset/Charset;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
      66: return

  private final java.util.ArrayList<java.lang.Integer> quickSort(java.util.ArrayList<java.lang.Integer>);
    Code:
       0: aload_1
       1: checkcast     #110                // class java/util/Collection
       4: invokeinterface #113,  1          // InterfaceMethod java/util/Collection.size:()I
       9: iconst_2
      10: if_icmpge     15
      13: aload_1
      14: areturn
      15: aload_1
      16: aload_1
      17: checkcast     #110                // class java/util/Collection
      20: invokeinterface #113,  1          // InterfaceMethod java/util/Collection.size:()I
      25: iconst_2
      26: idiv
      27: invokevirtual #116                // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
      30: dup
      31: ldc           #118                // String get(...)
      33: invokestatic  #121                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      36: checkcast     #123                // class java/lang/Number
      39: invokevirtual #126                // Method java/lang/Number.intValue:()I
      42: istore_2
      43: aload_1
      44: checkcast     #128                // class java/lang/Iterable
      47: astore        5
      49: iconst_0
      50: istore        6
      52: aload         5
      54: astore        7
      56: new           #10                 // class java/util/ArrayList
      59: dup
      60: invokespecial #11                 // Method java/util/ArrayList."<init>":()V
      63: checkcast     #110                // class java/util/Collection
      66: astore        8
      68: iconst_0
      69: istore        9
      71: aload         7
      73: invokeinterface #132,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      78: astore        10
      80: aload         10
      82: invokeinterface #138,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      87: ifeq          139
      90: aload         10
      92: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      97: astore        11
      99: aload         11
     101: checkcast     #123                // class java/lang/Number
     104: invokevirtual #126                // Method java/lang/Number.intValue:()I
     107: istore        12
     109: iconst_0
     110: istore        13
     112: iload         12
     114: iload_2
     115: if_icmpne     122
     118: iconst_1
     119: goto          123
     122: iconst_0
     123: ifeq          80
     126: aload         8
     128: aload         11
     130: invokeinterface #146,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     135: pop
     136: goto          80
     139: aload         8
     141: checkcast     #148                // class java/util/List
     144: nop
     145: checkcast     #10                 // class java/util/ArrayList
     148: astore_3
     149: aload_1
     150: checkcast     #128                // class java/lang/Iterable
     153: astore        6
     155: iconst_0
     156: istore        7
     158: aload         6
     160: astore        8
     162: new           #10                 // class java/util/ArrayList
     165: dup
     166: invokespecial #11                 // Method java/util/ArrayList."<init>":()V
     169: checkcast     #110                // class java/util/Collection
     172: astore        9
     174: iconst_0
     175: istore        10
     177: aload         8
     179: invokeinterface #132,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     184: astore        11
     186: aload         11
     188: invokeinterface #138,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     193: ifeq          245
     196: aload         11
     198: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     203: astore        12
     205: aload         12
     207: checkcast     #123                // class java/lang/Number
     210: invokevirtual #126                // Method java/lang/Number.intValue:()I
     213: istore        13
     215: iconst_0
     216: istore        14
     218: iload         13
     220: iload_2
     221: if_icmpge     228
     224: iconst_1
     225: goto          229
     228: iconst_0
     229: ifeq          186
     232: aload         9
     234: aload         12
     236: invokeinterface #146,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     241: pop
     242: goto          186
     245: aload         9
     247: checkcast     #148                // class java/util/List
     250: nop
     251: checkcast     #10                 // class java/util/ArrayList
     254: astore        4
     256: aload_1
     257: checkcast     #128                // class java/lang/Iterable
     260: astore        7
     262: iconst_0
     263: istore        8
     265: aload         7
     267: astore        9
     269: new           #10                 // class java/util/ArrayList
     272: dup
     273: invokespecial #11                 // Method java/util/ArrayList."<init>":()V
     276: checkcast     #110                // class java/util/Collection
     279: astore        10
     281: iconst_0
     282: istore        11
     284: aload         9
     286: invokeinterface #132,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     291: astore        12
     293: aload         12
     295: invokeinterface #138,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     300: ifeq          352
     303: aload         12
     305: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     310: astore        13
     312: aload         13
     314: checkcast     #123                // class java/lang/Number
     317: invokevirtual #126                // Method java/lang/Number.intValue:()I
     320: istore        14
     322: iconst_0
     323: istore        15
     325: iload         14
     327: iload_2
     328: if_icmple     335
     331: iconst_1
     332: goto          336
     335: iconst_0
     336: ifeq          293
     339: aload         10
     341: aload         13
     343: invokeinterface #146,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     348: pop
     349: goto          293
     352: aload         10
     354: checkcast     #148                // class java/util/List
     357: nop
     358: checkcast     #10                 // class java/util/ArrayList
     361: astore        5
     363: aload_0
     364: aload         4
     366: invokespecial #150                // Method quickSort:(Ljava/util/ArrayList;)Ljava/util/ArrayList;
     369: checkcast     #110                // class java/util/Collection
     372: aload_3
     373: checkcast     #128                // class java/lang/Iterable
     376: invokestatic  #156                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     379: checkcast     #110                // class java/util/Collection
     382: aload_0
     383: aload         5
     385: invokespecial #150                // Method quickSort:(Ljava/util/ArrayList;)Ljava/util/ArrayList;
     388: checkcast     #128                // class java/lang/Iterable
     391: invokestatic  #156                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     394: dup
     395: ldc           #158                // String null cannot be cast to non-null type java.util.ArrayList<kotlin.Int>
     397: invokestatic  #161                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;Ljava/lang/String;)V
     400: checkcast     #10                 // class java/util/ArrayList
     403: areturn

  public final void solvePartOne();
    Code:
       0: aload_0
       1: getfield      #15                 // Field inputList:Ljava/util/ArrayList;
       4: checkcast     #110                // class java/util/Collection
       7: invokeinterface #113,  1          // InterfaceMethod java/util/Collection.size:()I
      12: ifne          21
      15: aload_0
      16: ldc           #182                // String src/data/DayOneInput.txt
      18: invokevirtual #184                // Method loadInputFile:(Ljava/lang/String;)V
      21: aload_0
      22: getfield      #15                 // Field inputList:Ljava/util/ArrayList;
      25: checkcast     #128                // class java/lang/Iterable
      28: astore_2
      29: iconst_0
      30: istore_3
      31: aload_2
      32: astore        4
      34: new           #10                 // class java/util/ArrayList
      37: dup
      38: invokespecial #11                 // Method java/util/ArrayList."<init>":()V
      41: checkcast     #110                // class java/util/Collection
      44: astore        5
      46: iconst_0
      47: istore        6
      49: aload         4
      51: invokeinterface #132,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      56: astore        7
      58: aload         7
      60: invokeinterface #138,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      65: ifeq          119
      68: aload         7
      70: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      75: astore        8
      77: aload         8
      79: checkcast     #123                // class java/lang/Number
      82: invokevirtual #126                // Method java/lang/Number.intValue:()I
      85: istore        9
      87: iconst_0
      88: istore        10
      90: iload         9
      92: sipush        2020
      95: if_icmpge     102
      98: iconst_1
      99: goto          103
     102: iconst_0
     103: ifeq          58
     106: aload         5
     108: aload         8
     110: invokeinterface #146,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     115: pop
     116: goto          58
     119: aload         5
     121: checkcast     #148                // class java/util/List
     124: nop
     125: astore_1
     126: aload_0
     127: aload_1
     128: checkcast     #10                 // class java/util/ArrayList
     131: invokespecial #150                // Method quickSort:(Ljava/util/ArrayList;)Ljava/util/ArrayList;
     134: astore_2
     135: aload_2
     136: invokevirtual #185                // Method java/util/ArrayList.iterator:()Ljava/util/Iterator;
     139: dup
     140: ldc           #187                // String iterator(...)
     142: invokestatic  #121                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     145: astore_3
     146: aload_3
     147: invokeinterface #138,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     152: ifeq          237
     155: aload_3
     156: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     161: dup
     162: ldc           #189                // String next(...)
     164: invokestatic  #121                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     167: checkcast     #123                // class java/lang/Number
     170: invokevirtual #126                // Method java/lang/Number.intValue:()I
     173: istore        4
     175: aload_2
     176: checkcast     #128                // class java/lang/Iterable
     179: invokestatic  #193                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     182: invokeinterface #194,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     187: astore        5
     189: aload         5
     191: invokeinterface #138,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     196: ifeq          146
     199: aload         5
     201: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     206: checkcast     #123                // class java/lang/Number
     209: invokevirtual #126                // Method java/lang/Number.intValue:()I
     212: istore        6
     214: iload         4
     216: iload         6
     218: iadd
     219: sipush        2020
     222: if_icmpne     189
     225: aload_0
     226: iload         4
     228: iload         6
     230: imul
     231: putfield      #23                 // Field partOneAnswer:I
     234: goto          237
     237: return

  public final void solvePartTwo();
    Code:
       0: aload_0
       1: getfield      #15                 // Field inputList:Ljava/util/ArrayList;
       4: checkcast     #110                // class java/util/Collection
       7: invokeinterface #113,  1          // InterfaceMethod java/util/Collection.size:()I
      12: ifne          21
      15: aload_0
      16: ldc           #182                // String src/data/DayOneInput.txt
      18: invokevirtual #184                // Method loadInputFile:(Ljava/lang/String;)V
      21: aload_0
      22: getfield      #15                 // Field inputList:Ljava/util/ArrayList;
      25: checkcast     #128                // class java/lang/Iterable
      28: astore_2
      29: iconst_0
      30: istore_3
      31: aload_2
      32: astore        4
      34: new           #10                 // class java/util/ArrayList
      37: dup
      38: invokespecial #11                 // Method java/util/ArrayList."<init>":()V
      41: checkcast     #110                // class java/util/Collection
      44: astore        5
      46: iconst_0
      47: istore        6
      49: aload         4
      51: invokeinterface #132,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      56: astore        7
      58: aload         7
      60: invokeinterface #138,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      65: ifeq          119
      68: aload         7
      70: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      75: astore        8
      77: aload         8
      79: checkcast     #123                // class java/lang/Number
      82: invokevirtual #126                // Method java/lang/Number.intValue:()I
      85: istore        9
      87: iconst_0
      88: istore        10
      90: iload         9
      92: sipush        2020
      95: if_icmpge     102
      98: iconst_1
      99: goto          103
     102: iconst_0
     103: ifeq          58
     106: aload         5
     108: aload         8
     110: invokeinterface #146,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     115: pop
     116: goto          58
     119: aload         5
     121: checkcast     #148                // class java/util/List
     124: nop
     125: astore_1
     126: aload_0
     127: aload_1
     128: checkcast     #10                 // class java/util/ArrayList
     131: invokespecial #150                // Method quickSort:(Ljava/util/ArrayList;)Ljava/util/ArrayList;
     134: astore_2
     135: aload_2
     136: invokevirtual #185                // Method java/util/ArrayList.iterator:()Ljava/util/Iterator;
     139: dup
     140: ldc           #187                // String iterator(...)
     142: invokestatic  #121                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     145: astore_3
     146: aload_3
     147: invokeinterface #138,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     152: ifeq          481
     155: aload_3
     156: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     161: dup
     162: ldc           #189                // String next(...)
     164: invokestatic  #121                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     167: checkcast     #123                // class java/lang/Number
     170: invokevirtual #126                // Method java/lang/Number.intValue:()I
     173: istore        4
     175: aload_2
     176: checkcast     #128                // class java/lang/Iterable
     179: astore        6
     181: iconst_0
     182: istore        7
     184: aload         6
     186: astore        8
     188: new           #10                 // class java/util/ArrayList
     191: dup
     192: invokespecial #11                 // Method java/util/ArrayList."<init>":()V
     195: checkcast     #110                // class java/util/Collection
     198: astore        9
     200: iconst_0
     201: istore        10
     203: aload         8
     205: invokeinterface #132,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     210: astore        11
     212: aload         11
     214: invokeinterface #138,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     219: ifeq          272
     222: aload         11
     224: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     229: astore        12
     231: aload         12
     233: checkcast     #123                // class java/lang/Number
     236: invokevirtual #126                // Method java/lang/Number.intValue:()I
     239: istore        13
     241: iconst_0
     242: istore        14
     244: iload         13
     246: iload         4
     248: if_icmpeq     255
     251: iconst_1
     252: goto          256
     255: iconst_0
     256: ifeq          212
     259: aload         9
     261: aload         12
     263: invokeinterface #146,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     268: pop
     269: goto          212
     272: aload         9
     274: checkcast     #148                // class java/util/List
     277: nop
     278: invokeinterface #194,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     283: astore        5
     285: aload         5
     287: invokeinterface #138,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     292: ifeq          146
     295: aload         5
     297: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     302: checkcast     #123                // class java/lang/Number
     305: invokevirtual #126                // Method java/lang/Number.intValue:()I
     308: istore        6
     310: aload_2
     311: checkcast     #128                // class java/lang/Iterable
     314: astore        8
     316: iconst_0
     317: istore        9
     319: aload         8
     321: astore        10
     323: new           #10                 // class java/util/ArrayList
     326: dup
     327: invokespecial #11                 // Method java/util/ArrayList."<init>":()V
     330: checkcast     #110                // class java/util/Collection
     333: astore        11
     335: iconst_0
     336: istore        12
     338: aload         10
     340: invokeinterface #132,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     345: astore        13
     347: aload         13
     349: invokeinterface #138,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     354: ifeq          414
     357: aload         13
     359: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     364: astore        14
     366: aload         14
     368: checkcast     #123                // class java/lang/Number
     371: invokevirtual #126                // Method java/lang/Number.intValue:()I
     374: istore        15
     376: iconst_0
     377: istore        16
     379: iload         15
     381: iload         4
     383: if_icmpeq     397
     386: iload         15
     388: iload         6
     390: if_icmpeq     397
     393: iconst_1
     394: goto          398
     397: iconst_0
     398: ifeq          347
     401: aload         11
     403: aload         14
     405: invokeinterface #146,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     410: pop
     411: goto          347
     414: aload         11
     416: checkcast     #148                // class java/util/List
     419: nop
     420: invokeinterface #194,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     425: astore        7
     427: aload         7
     429: invokeinterface #138,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     434: ifeq          285
     437: aload         7
     439: invokeinterface #142,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     444: checkcast     #123                // class java/lang/Number
     447: invokevirtual #126                // Method java/lang/Number.intValue:()I
     450: istore        8
     452: iload         4
     454: iload         6
     456: iadd
     457: iload         8
     459: iadd
     460: sipush        2020
     463: if_icmpne     427
     466: aload_0
     467: iload         4
     469: iload         6
     471: imul
     472: iload         8
     474: imul
     475: putfield      #30                 // Field partTwoAnswer:I
     478: goto          481
     481: return

  private static final kotlin.Unit loadInputFile$lambda$0(twentytwenty.DayOne, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #208                // String it
       3: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getfield      #15                 // Field inputList:Ljava/util/ArrayList;
      10: aload_1
      11: invokestatic  #214                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      14: invokestatic  #218                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      17: invokevirtual #219                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      20: pop
      21: getstatic     #225                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      24: areturn
}


package io.gitlab.arturbosch.detekt.formatting

import java.util.ArrayList

/**
 * Extracted and adapted from KtLint.
 */

internal fun calculateLineColByOffset(text: String): (offset: Int) -> Pair<Int, Int> {
    var i = -1
    val e = text.length
    val arr = ArrayList<Int>()
    do {
        arr.add(i + 1)
        i = text.indexOf('\n', i + 1)
    } while (i != -1)
    arr.add(e + if (arr.last() == e) 1 else 0)
    val segmentTree = SegmentTree(arr.toTypedArray())
    return { offset ->
        val line = segmentTree.indexOf(offset)
        if (line != -1) {
            val col = offset - segmentTree.get(line).left
            line + 1 to col + 1
        } else {
            1 to 1
        }
    }
}

internal fun calculateLineBreakOffset(fileContent: String): (offset: Int) -> Int {
    val arr = ArrayList<Int>()
    var i = 0
    do {
        arr.add(i)
        i = fileContent.indexOf("\r\n", i + 1)
    } while (i != -1)
    arr.add(fileContent.length)
    return if (arr.size != 2) {
        SegmentTree(arr.toTypedArray()).let { return { offset -> it.indexOf(offset) } }
    } else { _ ->
        0
    }
}

internal class SegmentTree(sortedArray: Array<Int>) {

    private val segments: List<Segment>

    fun get(i: Int): Segment = segments[i]
    fun indexOf(v: Int): Int = binarySearch(v, 0, this.segments.size - 1)

    private fun binarySearch(v: Int, l: Int, r: Int): Int = if (l > r) -1 else {
        val i = l + (r - l) / 2
        val s = segments[i]
        if (v < s.left) binarySearch(v, l, i - 1)
        else (if (s.right < v) binarySearch(v, i + 1, r) else i)
    }

    init {
        require(sortedArray.size > 1) { "At least two data points are required" }
        sortedArray.reduce { r, v -> require(r <= v) { "Data points are not sorted (ASC)" }; v }
        segments = sortedArray.take(sortedArray.size - 1)
                .mapIndexed { i: Int, v: Int -> Segment(v, sortedArray[i + 1] - 1) }
    }
}

internal data class Segment(val left: Int, val right: Int)

Compiled from "OffsetsToLineColumn.kt"
public final class io.gitlab.arturbosch.detekt.formatting.OffsetsToLineColumnKt {
  public static final kotlin.jvm.functions.Function1<java.lang.Integer, kotlin.Pair<java.lang.Integer, java.lang.Integer>> calculateLineColByOffset(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #10                 // String text
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_m1
       7: istore_1
       8: aload_0
       9: invokevirtual #22                 // Method java/lang/String.length:()I
      12: istore_2
      13: new           #24                 // class java/util/ArrayList
      16: dup
      17: invokespecial #28                 // Method java/util/ArrayList."<init>":()V
      20: astore_3
      21: aload_3
      22: iload_1
      23: iconst_1
      24: iadd
      25: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      28: invokevirtual #38                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      31: pop
      32: aload_0
      33: checkcast     #40                 // class java/lang/CharSequence
      36: bipush        10
      38: iload_1
      39: iconst_1
      40: iadd
      41: iconst_0
      42: iconst_4
      43: aconst_null
      44: invokestatic  #46                 // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;CIZILjava/lang/Object;)I
      47: istore_1
      48: iload_1
      49: iconst_m1
      50: if_icmpne     21
      53: aload_3
      54: iload_2
      55: aload_3
      56: checkcast     #48                 // class java/util/List
      59: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      62: checkcast     #56                 // class java/lang/Number
      65: invokevirtual #59                 // Method java/lang/Number.intValue:()I
      68: iload_2
      69: if_icmpne     76
      72: iconst_1
      73: goto          77
      76: iconst_0
      77: iadd
      78: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      81: invokevirtual #38                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      84: pop
      85: new           #61                 // class io/gitlab/arturbosch/detekt/formatting/SegmentTree
      88: dup
      89: aload_3
      90: checkcast     #63                 // class java/util/Collection
      93: astore        5
      95: iconst_0
      96: istore        6
      98: aload         5
     100: astore        7
     102: aload         7
     104: iconst_0
     105: anewarray     #30                 // class java/lang/Integer
     108: invokeinterface #67,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     113: checkcast     #69                 // class "[Ljava/lang/Integer;"
     116: invokespecial #72                 // Method io/gitlab/arturbosch/detekt/formatting/SegmentTree."<init>":([Ljava/lang/Integer;)V
     119: astore        4
     121: aload         4
     123: invokedynamic #92,  0             // InvokeDynamic #0:invoke:(Lio/gitlab/arturbosch/detekt/formatting/SegmentTree;)Lkotlin/jvm/functions/Function1;
     128: areturn

  public static final kotlin.jvm.functions.Function1<java.lang.Integer, java.lang.Integer> calculateLineBreakOffset(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #108                // String fileContent
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #24                 // class java/util/ArrayList
       9: dup
      10: invokespecial #28                 // Method java/util/ArrayList."<init>":()V
      13: astore_1
      14: iconst_0
      15: istore_2
      16: aload_1
      17: iload_2
      18: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      21: invokevirtual #38                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      24: pop
      25: aload_0
      26: checkcast     #40                 // class java/lang/CharSequence
      29: ldc           #110                // String \r\n
      31: iload_2
      32: iconst_1
      33: iadd
      34: iconst_0
      35: iconst_4
      36: aconst_null
      37: invokestatic  #113                // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
      40: istore_2
      41: iload_2
      42: iconst_m1
      43: if_icmpne     16
      46: aload_1
      47: aload_0
      48: invokevirtual #22                 // Method java/lang/String.length:()I
      51: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      54: invokevirtual #38                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      57: pop
      58: aload_1
      59: invokevirtual #116                // Method java/util/ArrayList.size:()I
      62: iconst_2
      63: if_icmpeq     111
      66: new           #61                 // class io/gitlab/arturbosch/detekt/formatting/SegmentTree
      69: dup
      70: aload_1
      71: checkcast     #63                 // class java/util/Collection
      74: astore_3
      75: iconst_0
      76: istore        4
      78: aload_3
      79: astore        5
      81: aload         5
      83: iconst_0
      84: anewarray     #30                 // class java/lang/Integer
      87: invokeinterface #67,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
      92: checkcast     #69                 // class "[Ljava/lang/Integer;"
      95: invokespecial #72                 // Method io/gitlab/arturbosch/detekt/formatting/SegmentTree."<init>":([Ljava/lang/Integer;)V
      98: astore        4
     100: iconst_0
     101: istore        5
     103: aload         4
     105: invokedynamic #124,  0            // InvokeDynamic #1:invoke:(Lio/gitlab/arturbosch/detekt/formatting/SegmentTree;)Lkotlin/jvm/functions/Function1;
     110: areturn
     111: invokedynamic #132,  0            // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function1;
     116: areturn

  private static final kotlin.Pair calculateLineColByOffset$lambda$0(io.gitlab.arturbosch.detekt.formatting.SegmentTree, int);
    Code:
       0: aload_0
       1: iload_1
       2: invokevirtual #137                // Method io/gitlab/arturbosch/detekt/formatting/SegmentTree.indexOf:(I)I
       5: istore_2
       6: iload_2
       7: iconst_m1
       8: if_icmpeq     40
      11: iload_1
      12: aload_0
      13: iload_2
      14: invokevirtual #141                // Method io/gitlab/arturbosch/detekt/formatting/SegmentTree.get:(I)Lio/gitlab/arturbosch/detekt/formatting/Segment;
      17: invokevirtual #146                // Method io/gitlab/arturbosch/detekt/formatting/Segment.getLeft:()I
      20: isub
      21: istore_3
      22: iload_2
      23: iconst_1
      24: iadd
      25: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      28: iload_3
      29: iconst_1
      30: iadd
      31: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      34: invokestatic  #152                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      37: goto          51
      40: iconst_1
      41: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      44: iconst_1
      45: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      48: invokestatic  #152                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      51: areturn

  private static final int calculateLineBreakOffset$lambda$2$lambda$1(io.gitlab.arturbosch.detekt.formatting.SegmentTree, int);
    Code:
       0: aload_0
       1: iload_1
       2: invokevirtual #137                // Method io/gitlab/arturbosch/detekt/formatting/SegmentTree.indexOf:(I)I
       5: ireturn

  private static final int calculateLineBreakOffset$lambda$3(int);
    Code:
       0: iconst_0
       1: ireturn
}


package day7

import kotlin.math.min

// Problem: You are given with an datastructure.array [1,4,5,3,6,8,4,0,8]
// 1. find the subarray of length 3 whose sum is equal to 12. // fixed length problem
// 2. find the minimum subarray whose sum is equal to 12. // dynamic window size length problem
// 3. find how many subarray whose sum is equal to 12. // dynamic window size length problem

fun fixedSizeSubArraySum(arr : IntArray, targetSum : Int) : Int{

    var runningSum = 0
    val windowSize = 3

    for ((index, value) in arr.withIndex()){
        runningSum += value

        if (index >= windowSize-1){
            if (runningSum == targetSum) {
                return index - (windowSize -1)
            }
            runningSum -= arr[index - (windowSize -1)]
        }
    }

    return -1 // If no datastructure.array found
}

fun minimumSubarrayWithTargetSum(arr: IntArray, targetSum: Int) : Int { // returns size of minimum subarray

    var windowSum = 0
    var windowStart = 0
    var minSubarraySize = Integer.MAX_VALUE

    arr.forEachIndexed{ windowEnd, value ->
        windowSum += value

        while (windowSum >= targetSum){
            if (windowSum == targetSum){
                minSubarraySize = min(minSubarraySize, windowEnd - windowStart + 1)
            }
            windowSum -= arr[windowStart]
            windowStart++
        }
    }

    return minSubarraySize // If no subarray with given sum found
}

fun howManySubarrayWithSumK(arr: IntArray, targetSum: Int) : Int { // returns size of minimum subarray

    var windowSum = 0
    var windowStart = 0
    var count = 0

    arr.forEachIndexed{ windowEnd, value ->
        windowSum += value

        while (windowSum >= targetSum){
            if (windowSum == targetSum){
                count++
            }
            windowSum -= arr[windowStart]
            windowStart++
        }
    }

    return count // If no subarray with given sum found
}

fun main(){

    val arr = intArrayOf(1,4,5,3,6,8,4,0,8)

      // case 1:
//    val index = fixedSizeSubArraySum( arr, 12)
//    if (index != -1){
//        println(arr.slice(index..index+2))
//    }else{
//        print("No subarray with given sum found.")
//    }

      // case 2:
//    val size = minimumSubarrayWithTargetSum(arr, 8)
//    if (size == Integer.MAX_VALUE){
//        println("No subarray found")
//    }else{
//        print("Size of datastructure.array whose sum is 12 : $size")
//    }

    // case 3:

    println(howManySubarrayWithSumK(arr, 12))
}

Compiled from "FindSubarrayWithSumK.kt"
public final class day7.FindSubarrayWithSumKKt {
  public static final int fixedSizeSubArraySum(int[], int);
    Code:
       0: aload_0
       1: ldc           #9                  // String arr
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: iconst_3
       9: istore_3
      10: iconst_0
      11: istore        4
      13: aload_0
      14: arraylength
      15: istore        5
      17: iload         4
      19: iload         5
      21: if_icmpge     76
      24: iload         4
      26: istore        6
      28: aload_0
      29: iload         4
      31: iaload
      32: istore        7
      34: iload_2
      35: iload         7
      37: iadd
      38: istore_2
      39: iload         6
      41: iload_3
      42: iconst_1
      43: isub
      44: if_icmplt     70
      47: iload_2
      48: iload_1
      49: if_icmpne     59
      52: iload         6
      54: iload_3
      55: iconst_1
      56: isub
      57: isub
      58: ireturn
      59: iload_2
      60: aload_0
      61: iload         6
      63: iload_3
      64: iconst_1
      65: isub
      66: isub
      67: iaload
      68: isub
      69: istore_2
      70: iinc          4, 1
      73: goto          17
      76: iconst_m1
      77: ireturn

  public static final int minimumSubarrayWithTargetSum(int[], int);
    Code:
       0: aload_0
       1: ldc           #9                  // String arr
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: iconst_0
       9: istore_3
      10: iconst_0
      11: istore        4
      13: ldc           #25                 // int 2147483647
      15: istore        4
      17: aload_0
      18: astore        5
      20: iconst_0
      21: istore        6
      23: iconst_0
      24: istore        7
      26: iconst_0
      27: istore        8
      29: aload         5
      31: arraylength
      32: istore        9
      34: iload         8
      36: iload         9
      38: if_icmpge     111
      41: aload         5
      43: iload         8
      45: iaload
      46: istore        10
      48: iload         7
      50: iinc          7, 1
      53: iload         10
      55: istore        11
      57: istore        12
      59: iconst_0
      60: istore        13
      62: iload_2
      63: iload         11
      65: iadd
      66: istore_2
      67: iload_2
      68: iload_1
      69: if_icmplt     103
      72: iload_2
      73: iload_1
      74: if_icmpne     90
      77: iload         4
      79: iload         12
      81: iload_3
      82: isub
      83: iconst_1
      84: iadd
      85: invokestatic  #31                 // Method java/lang/Math.min:(II)I
      88: istore        4
      90: iload_2
      91: aload_0
      92: iload_3
      93: iaload
      94: isub
      95: istore_2
      96: iload_3
      97: iconst_1
      98: iadd
      99: istore_3
     100: goto          67
     103: nop
     104: nop
     105: iinc          8, 1
     108: goto          34
     111: nop
     112: iload         4
     114: ireturn

  public static final int howManySubarrayWithSumK(int[], int);
    Code:
       0: aload_0
       1: ldc           #9                  // String arr
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: iconst_0
       9: istore_3
      10: iconst_0
      11: istore        4
      13: aload_0
      14: astore        5
      16: iconst_0
      17: istore        6
      19: iconst_0
      20: istore        7
      22: iconst_0
      23: istore        8
      25: aload         5
      27: arraylength
      28: istore        9
      30: iload         8
      32: iload         9
      34: if_icmpge     100
      37: aload         5
      39: iload         8
      41: iaload
      42: istore        10
      44: iload         7
      46: iinc          7, 1
      49: iload         10
      51: istore        11
      53: istore        12
      55: iconst_0
      56: istore        13
      58: iload_2
      59: iload         11
      61: iadd
      62: istore_2
      63: iload_2
      64: iload_1
      65: if_icmplt     92
      68: iload_2
      69: iload_1
      70: if_icmpne     79
      73: iload         4
      75: iconst_1
      76: iadd
      77: istore        4
      79: iload_2
      80: aload_0
      81: iload_3
      82: iaload
      83: isub
      84: istore_2
      85: iload_3
      86: iconst_1
      87: iadd
      88: istore_3
      89: goto          63
      92: nop
      93: nop
      94: iinc          8, 1
      97: goto          30
     100: nop
     101: iload         4
     103: ireturn

  public static final void main();
    Code:
       0: bipush        9
       2: newarray       int
       4: astore_1
       5: aload_1
       6: iconst_0
       7: iconst_1
       8: iastore
       9: aload_1
      10: iconst_1
      11: iconst_4
      12: iastore
      13: aload_1
      14: iconst_2
      15: iconst_5
      16: iastore
      17: aload_1
      18: iconst_3
      19: iconst_3
      20: iastore
      21: aload_1
      22: iconst_4
      23: bipush        6
      25: iastore
      26: aload_1
      27: iconst_5
      28: bipush        8
      30: iastore
      31: aload_1
      32: bipush        6
      34: iconst_4
      35: iastore
      36: aload_1
      37: bipush        7
      39: iconst_0
      40: iastore
      41: aload_1
      42: bipush        8
      44: bipush        8
      46: iastore
      47: aload_1
      48: astore_0
      49: aload_0
      50: bipush        12
      52: invokestatic  #47                 // Method howManySubarrayWithSumK:([II)I
      55: istore_1
      56: getstatic     #53                 // Field java/lang/System.out:Ljava/io/PrintStream;
      59: iload_1
      60: invokevirtual #59                 // Method java/io/PrintStream.println:(I)V
      63: return

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


package day8

// Problem : Given an datastructure.array of integers, you have find if there are two numbers whose sum is equal to k.
// 2 Sum - k=2
class subarraySumAlgorithm {

    fun findTwoSum(a: IntArray, k: Int): Boolean {
        var end = a.size - 1
        var start = 0
        a.sort()
        while (start < a.size) {
            val sum = a[start] + a[end]
            when {
                sum > k -> {
                    end--
                }
                sum < k -> {
                    start++
                }
                else -> {
                    return true
                }
            }
        }
        return false
    }

    fun findThreeSum(a: IntArray, k: Int): Boolean {
        var start = 0
        val end = a.size - 1
        while (start < end){
            if (findTwoSum(a.copyOfRange(start+1, end), k -a[start])){
                return true
            }
            start++
        }
        return false
    }
}

fun main() {
    val twoSumAlgorithm = subarraySumAlgorithm()
    val a = intArrayOf(2, -1, 0, 3, 2, 1, -1, 2)
    a.sort()
//    println(twoSumAlgorithm.findTwoSum(a, 6))
    println(twoSumAlgorithm.findThreeSum(a, 0))
    println(twoSumAlgorithm.findThreeSum(a, 3))
    println(twoSumAlgorithm.findThreeSum(a, 11))
}

Compiled from "subarraySumAlgorithm.kt"
public final class day8.subarraySumAlgorithm {
  public day8.subarraySumAlgorithm();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final boolean findTwoSum(int[], int);
    Code:
       0: aload_1
       1: ldc           #15                 // String a
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: arraylength
       8: iconst_1
       9: isub
      10: istore_3
      11: iconst_0
      12: istore        4
      14: aload_1
      15: invokestatic  #27                 // Method kotlin/collections/ArraysKt.sort:([I)V
      18: iload         4
      20: aload_1
      21: arraylength
      22: if_icmpge     62
      25: aload_1
      26: iload         4
      28: iaload
      29: aload_1
      30: iload_3
      31: iaload
      32: iadd
      33: istore        5
      35: nop
      36: iload         5
      38: iload_2
      39: if_icmple     48
      42: iinc          3, -1
      45: goto          18
      48: iload         5
      50: iload_2
      51: if_icmpge     60
      54: iinc          4, 1
      57: goto          18
      60: iconst_1
      61: ireturn
      62: iconst_0
      63: ireturn

  public final boolean findThreeSum(int[], int);
    Code:
       0: aload_1
       1: ldc           #15                 // String a
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_3
       8: aload_1
       9: arraylength
      10: iconst_1
      11: isub
      12: istore        4
      14: iload_3
      15: iload         4
      17: if_icmpge     49
      20: aload_0
      21: aload_1
      22: iload_3
      23: iconst_1
      24: iadd
      25: iload         4
      27: invokestatic  #38                 // Method kotlin/collections/ArraysKt.copyOfRange:([III)[I
      30: iload_2
      31: aload_1
      32: iload_3
      33: iaload
      34: isub
      35: invokevirtual #40                 // Method findTwoSum:([II)Z
      38: ifeq          43
      41: iconst_1
      42: ireturn
      43: iinc          3, 1
      46: goto          14
      49: iconst_0
      50: ireturn
}

Compiled from "subarraySumAlgorithm.kt"
public final class day8.SubarraySumAlgorithmKt {
  public static final void main();
    Code:
       0: new           #8                  // class day8/subarraySumAlgorithm
       3: dup
       4: invokespecial #11                 // Method day8/subarraySumAlgorithm."<init>":()V
       7: astore_0
       8: bipush        8
      10: newarray       int
      12: astore_2
      13: aload_2
      14: iconst_0
      15: iconst_2
      16: iastore
      17: aload_2
      18: iconst_1
      19: iconst_m1
      20: iastore
      21: aload_2
      22: iconst_2
      23: iconst_0
      24: iastore
      25: aload_2
      26: iconst_3
      27: iconst_3
      28: iastore
      29: aload_2
      30: iconst_4
      31: iconst_2
      32: iastore
      33: aload_2
      34: iconst_5
      35: iconst_1
      36: iastore
      37: aload_2
      38: bipush        6
      40: iconst_m1
      41: iastore
      42: aload_2
      43: bipush        7
      45: iconst_2
      46: iastore
      47: aload_2
      48: astore_1
      49: aload_1
      50: invokestatic  #17                 // Method kotlin/collections/ArraysKt.sort:([I)V
      53: aload_0
      54: aload_1
      55: iconst_0
      56: invokevirtual #21                 // Method day8/subarraySumAlgorithm.findThreeSum:([II)Z
      59: istore_2
      60: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      63: iload_2
      64: invokevirtual #33                 // Method java/io/PrintStream.println:(Z)V
      67: aload_0
      68: aload_1
      69: iconst_3
      70: invokevirtual #21                 // Method day8/subarraySumAlgorithm.findThreeSum:([II)Z
      73: istore_2
      74: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      77: iload_2
      78: invokevirtual #33                 // Method java/io/PrintStream.println:(Z)V
      81: aload_0
      82: aload_1
      83: bipush        11
      85: invokevirtual #21                 // Method day8/subarraySumAlgorithm.findThreeSum:([II)Z
      88: istore_2
      89: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      92: iload_2
      93: invokevirtual #33                 // Method java/io/PrintStream.println:(Z)V
      96: return

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


package day10

import kotlin.math.abs

/*
Given an datastructure.array of time datastructure.strings times, return the smallest difference between any two times
in minutes.

Example:
Input: ["00:03", "23:59", "12:03"]
Output: 4
Input: The closest 2 times are "00:03" and "23:59" (by wrap-around), and they differ by
4 minutes.

Constraints:
All datastructure.strings will be non-empty and in the format HH:mm
*/

fun main(){

    var min = Integer.MAX_VALUE
    val input = listOf("00:03", "23:59", "12:03")
    var pair : Pair<Int, Int> = Pair(-1,-1)
    for( i in input.indices){
        for (j in i+1 until input.size){
            val d = getDifference(input[i], input[j])
            if (min > d){
                min = d
                pair = Pair(i, j)
            }
        }
    }

    println("diff = <${pair.first}, ${pair.second}>")
}

fun getDifference(first: String, second: String ) : Int {
    return abs(getMinutes(first) - getMinutes(second))
}

fun getMinutes(time: String): Int {
    val t = time.split(":")
    val h : Int
    h = if (t[0] == "00") {
        24
    }else{
        t[0].toInt()
    }

    val m = t[1].toInt()
    return abs(h * 60 + m)
}

Compiled from "MinimumTimeDiff.kt"
public final class day10.MinimumTimeDiffKt {
  public static final void main();
    Code:
       0: ldc           #7                  // int 2147483647
       2: istore_0
       3: iconst_3
       4: anewarray     #9                  // class java/lang/String
       7: astore_2
       8: aload_2
       9: iconst_0
      10: ldc           #11                 // String 00:03
      12: aastore
      13: aload_2
      14: iconst_1
      15: ldc           #13                 // String 23:59
      17: aastore
      18: aload_2
      19: iconst_2
      20: ldc           #15                 // String 12:03
      22: aastore
      23: aload_2
      24: invokestatic  #21                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      27: astore_1
      28: new           #23                 // class kotlin/Pair
      31: dup
      32: iconst_m1
      33: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      36: iconst_m1
      37: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      40: invokespecial #33                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      43: astore_2
      44: iconst_0
      45: istore_3
      46: aload_1
      47: checkcast     #35                 // class java/util/Collection
      50: invokeinterface #39,  1           // InterfaceMethod java/util/Collection.size:()I
      55: istore        4
      57: iload_3
      58: iload         4
      60: if_icmpge     147
      63: iload_3
      64: iconst_1
      65: iadd
      66: istore        5
      68: aload_1
      69: invokeinterface #42,  1           // InterfaceMethod java/util/List.size:()I
      74: istore        6
      76: iload         5
      78: iload         6
      80: if_icmpge     141
      83: aload_1
      84: iload_3
      85: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      90: checkcast     #9                  // class java/lang/String
      93: aload_1
      94: iload         5
      96: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     101: checkcast     #9                  // class java/lang/String
     104: invokestatic  #50                 // Method getDifference:(Ljava/lang/String;Ljava/lang/String;)I
     107: istore        7
     109: iload_0
     110: iload         7
     112: if_icmple     135
     115: iload         7
     117: istore_0
     118: new           #23                 // class kotlin/Pair
     121: dup
     122: iload_3
     123: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     126: iload         5
     128: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     131: invokespecial #33                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     134: astore_2
     135: iinc          5, 1
     138: goto          76
     141: iinc          3, 1
     144: goto          57
     147: new           #52                 // class java/lang/StringBuilder
     150: dup
     151: invokespecial #54                 // Method java/lang/StringBuilder."<init>":()V
     154: ldc           #56                 // String diff = <
     156: invokevirtual #60                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     159: aload_2
     160: invokevirtual #64                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     163: checkcast     #66                 // class java/lang/Number
     166: invokevirtual #69                 // Method java/lang/Number.intValue:()I
     169: invokevirtual #72                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     172: ldc           #74                 // String ,
     174: invokevirtual #60                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     177: aload_2
     178: invokevirtual #77                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     181: checkcast     #66                 // class java/lang/Number
     184: invokevirtual #69                 // Method java/lang/Number.intValue:()I
     187: invokevirtual #72                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     190: bipush        62
     192: invokevirtual #80                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     195: invokevirtual #84                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     198: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
     201: swap
     202: invokevirtual #96                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     205: return

  public static final int getDifference(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #108                // String first
       3: invokestatic  #114                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #116                // String second
       9: invokestatic  #114                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokestatic  #120                // Method getMinutes:(Ljava/lang/String;)I
      16: aload_1
      17: invokestatic  #120                // Method getMinutes:(Ljava/lang/String;)I
      20: isub
      21: invokestatic  #126                // Method java/lang/Math.abs:(I)I
      24: ireturn

  public static final int getMinutes(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #129                // String time
       3: invokestatic  #114                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #131                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #9                  // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc           #133                // String :
      19: aastore
      20: aload_2
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #139                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: astore_1
      30: iconst_0
      31: istore_2
      32: aload_1
      33: iconst_0
      34: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      39: ldc           #141                // String 00
      41: invokestatic  #145                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      44: ifeq          52
      47: bipush        24
      49: goto          65
      52: aload_1
      53: iconst_0
      54: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      59: checkcast     #9                  // class java/lang/String
      62: invokestatic  #148                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      65: istore_2
      66: aload_1
      67: iconst_1
      68: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      73: checkcast     #9                  // class java/lang/String
      76: invokestatic  #148                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      79: istore_3
      80: iload_2
      81: bipush        60
      83: imul
      84: iload_3
      85: iadd
      86: invokestatic  #126                // Method java/lang/Math.abs:(I)I
      89: ireturn

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


package datastructure.heap

/**
 * <> Heap: Maximum Element in a Stream
Implement a function named streamMax that processes a stream of integers and returns the maximum number encountered so far for each input number.
This function should take in an array of integers and return a list of integers.
Given an array of integers, your function should iterate over the array and for each number, it should find the maximum number in the array up until that point, including the current number.

int[] nums = {1, 5, 2, 9, 3, 6, 8};
List<Integer> result = streamMax(nums);
// Expected output: [1, 5, 5, 9, 9, 9, 9]
// Explanation: The maximum number for the first number is 1,
// for the first two numbers is 5, for the first three numbers is 5, and so on.
 * */
class StreamMax {

    fun findStreamMax(nums: IntArray): IntArray {

        val result = IntArray(nums.size) { Int.MIN_VALUE }

        val heap = Heap()

        nums.forEachIndexed { index, value ->
            heap.insert(value)
            result[index] = heap.getHeap()[0]
        }

        return result
    }
}

fun main() {
    val streamMax = StreamMax()
    // Test case 1
    // Test case 1
    val nums1 = intArrayOf(1, 5, 2, 9, 3, 6, 8)
    println("Test case 1:")
    println("Input: [1, 5, 2, 9, 3, 6, 8]")
    println("Expected output: [1, 5, 5, 9, 9, 9, 9]")
    val output = streamMax.findStreamMax(nums1)
    output.forEach { print("$it, ") }
    println()
    // Test case 2

    // Test case 2
    val nums2 = intArrayOf(10, 2, 5, 1, 0, 11, 6)
    println("Test case 2:")
    println("Input: [10, 2, 5, 1, 0, 11, 6]")
    println("Expected output: [10, 10, 10, 10, 10, 11, 11]")
    val output2 = streamMax.findStreamMax(nums2)
    output2.forEach { print("$it, ") }
    println()

}

Compiled from "StreamMax.kt"
public final class datastructure.heap.StreamMaxKt {
  public static final void main();
    Code:
       0: new           #8                  // class datastructure/heap/StreamMax
       3: dup
       4: invokespecial #11                 // Method datastructure/heap/StreamMax."<init>":()V
       7: astore_0
       8: bipush        7
      10: newarray       int
      12: astore_2
      13: aload_2
      14: iconst_0
      15: iconst_1
      16: iastore
      17: aload_2
      18: iconst_1
      19: iconst_5
      20: iastore
      21: aload_2
      22: iconst_2
      23: iconst_2
      24: iastore
      25: aload_2
      26: iconst_3
      27: bipush        9
      29: iastore
      30: aload_2
      31: iconst_4
      32: iconst_3
      33: iastore
      34: aload_2
      35: iconst_5
      36: bipush        6
      38: iastore
      39: aload_2
      40: bipush        6
      42: bipush        8
      44: iastore
      45: aload_2
      46: astore_1
      47: ldc           #13                 // String Test case 1:
      49: getstatic     #19                 // Field java/lang/System.out:Ljava/io/PrintStream;
      52: swap
      53: invokevirtual #25                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      56: ldc           #27                 // String Input: [1, 5, 2, 9, 3, 6, 8]
      58: getstatic     #19                 // Field java/lang/System.out:Ljava/io/PrintStream;
      61: swap
      62: invokevirtual #25                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      65: ldc           #29                 // String Expected output: [1, 5, 5, 9, 9, 9, 9]
      67: getstatic     #19                 // Field java/lang/System.out:Ljava/io/PrintStream;
      70: swap
      71: invokevirtual #25                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      74: aload_0
      75: aload_1
      76: invokevirtual #33                 // Method datastructure/heap/StreamMax.findStreamMax:([I)[I
      79: astore_2
      80: aload_2
      81: astore_3
      82: iconst_0
      83: istore        4
      85: iconst_0
      86: istore        5
      88: aload_3
      89: arraylength
      90: istore        6
      92: iload         5
      94: iload         6
      96: if_icmpge     147
      99: aload_3
     100: iload         5
     102: iaload
     103: istore        7
     105: iload         7
     107: istore        8
     109: iconst_0
     110: istore        9
     112: new           #35                 // class java/lang/StringBuilder
     115: dup
     116: invokespecial #36                 // Method java/lang/StringBuilder."<init>":()V
     119: iload         8
     121: invokevirtual #40                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     124: ldc           #42                 // String ,
     126: invokevirtual #45                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     129: invokevirtual #49                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     132: getstatic     #19                 // Field java/lang/System.out:Ljava/io/PrintStream;
     135: swap
     136: invokevirtual #52                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     139: nop
     140: nop
     141: iinc          5, 1
     144: goto          92
     147: nop
     148: getstatic     #19                 // Field java/lang/System.out:Ljava/io/PrintStream;
     151: invokevirtual #54                 // Method java/io/PrintStream.println:()V
     154: bipush        7
     156: newarray       int
     158: astore        4
     160: aload         4
     162: iconst_0
     163: bipush        10
     165: iastore
     166: aload         4
     168: iconst_1
     169: iconst_2
     170: iastore
     171: aload         4
     173: iconst_2
     174: iconst_5
     175: iastore
     176: aload         4
     178: iconst_3
     179: iconst_1
     180: iastore
     181: aload         4
     183: iconst_4
     184: iconst_0
     185: iastore
     186: aload         4
     188: iconst_5
     189: bipush        11
     191: iastore
     192: aload         4
     194: bipush        6
     196: bipush        6
     198: iastore
     199: aload         4
     201: astore_3
     202: ldc           #56                 // String Test case 2:
     204: getstatic     #19                 // Field java/lang/System.out:Ljava/io/PrintStream;
     207: swap
     208: invokevirtual #25                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     211: ldc           #58                 // String Input: [10, 2, 5, 1, 0, 11, 6]
     213: getstatic     #19                 // Field java/lang/System.out:Ljava/io/PrintStream;
     216: swap
     217: invokevirtual #25                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     220: ldc           #60                 // String Expected output: [10, 10, 10, 10, 10, 11, 11]
     222: getstatic     #19                 // Field java/lang/System.out:Ljava/io/PrintStream;
     225: swap
     226: invokevirtual #25                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     229: aload_0
     230: aload_3
     231: invokevirtual #33                 // Method datastructure/heap/StreamMax.findStreamMax:([I)[I
     234: astore        4
     236: aload         4
     238: astore        5
     240: iconst_0
     241: istore        6
     243: iconst_0
     244: istore        7
     246: aload         5
     248: arraylength
     249: istore        8
     251: iload         7
     253: iload         8
     255: if_icmpge     307
     258: aload         5
     260: iload         7
     262: iaload
     263: istore        9
     265: iload         9
     267: istore        10
     269: iconst_0
     270: istore        11
     272: new           #35                 // class java/lang/StringBuilder
     275: dup
     276: invokespecial #36                 // Method java/lang/StringBuilder."<init>":()V
     279: iload         10
     281: invokevirtual #40                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     284: ldc           #42                 // String ,
     286: invokevirtual #45                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     289: invokevirtual #49                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     292: getstatic     #19                 // Field java/lang/System.out:Ljava/io/PrintStream;
     295: swap
     296: invokevirtual #52                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     299: nop
     300: nop
     301: iinc          7, 1
     304: goto          251
     307: nop
     308: getstatic     #19                 // Field java/lang/System.out:Ljava/io/PrintStream;
     311: invokevirtual #54                 // Method java/io/PrintStream.println:()V
     314: return

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

Compiled from "StreamMax.kt"
public final class datastructure.heap.StreamMax {
  public datastructure.heap.StreamMax();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int[] findStreamMax(int[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String nums
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_3
       8: aload_1
       9: arraylength
      10: istore        4
      12: iload         4
      14: newarray       int
      16: astore        5
      18: iload_3
      19: iload         4
      21: if_icmpge     40
      24: iload_3
      25: istore        6
      27: aload         5
      29: iload         6
      31: ldc           #22                 // int -2147483648
      33: iastore
      34: iinc          3, 1
      37: goto          18
      40: aload         5
      42: astore_2
      43: new           #24                 // class datastructure/heap/Heap
      46: dup
      47: invokespecial #25                 // Method datastructure/heap/Heap."<init>":()V
      50: astore_3
      51: aload_1
      52: astore        4
      54: iconst_0
      55: istore        5
      57: iconst_0
      58: istore        6
      60: iconst_0
      61: istore        7
      63: aload         4
      65: arraylength
      66: istore        8
      68: iload         7
      70: iload         8
      72: if_icmpge     130
      75: aload         4
      77: iload         7
      79: iaload
      80: istore        9
      82: iload         6
      84: iinc          6, 1
      87: iload         9
      89: istore        10
      91: istore        11
      93: iconst_0
      94: istore        12
      96: aload_3
      97: iload         10
      99: invokevirtual #29                 // Method datastructure/heap/Heap.insert:(I)V
     102: aload_2
     103: iload         11
     105: aload_3
     106: invokevirtual #33                 // Method datastructure/heap/Heap.getHeap:()Ljava/util/List;
     109: iconst_0
     110: invokeinterface #39,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     115: checkcast     #41                 // class java/lang/Number
     118: invokevirtual #45                 // Method java/lang/Number.intValue:()I
     121: iastore
     122: nop
     123: nop
     124: iinc          7, 1
     127: goto          68
     130: nop
     131: aload_2
     132: areturn
}