Skip to content

Instantly share code, notes, and snippets.

@Rugal
Created August 13, 2018 22:51
Show Gist options
  • Save Rugal/8335a9d793a581358ce2aa7aa8504529 to your computer and use it in GitHub Desktop.
Save Rugal/8335a9d793a581358ce2aa7aa8504529 to your computer and use it in GitHub Desktop.
CapitalOne

1

    // Complete the fizzBuzz function below.
    static void fizzBuzz(int n) {
      for (int i = 1; i <= n; ++i) {
        if(i % 3 == 0 || i % 5 == 0) {
          print(i); 
        } else {
          System.out.println(i);
        }
      }
    }
      
    // Complete the fizzBuzz function below.
    static void print(int n) {
      if (n % 3 == 0 && n % 5 == 0) {
        System.out.println("FizzBuzz");
        return;
      }
      if (n % 3 == 0) {
        System.out.println("Fizz");
        return;
      }
      if (n % 5 == 0) {
        System.out.println("Buzz");
      }
    }

2

/*
 * Complete the function below.
 */
/*
For your reference:
LinkedListNode {
    int val;
    LinkedListNode *next;
};
*/

    static LinkedListNode removeNodes(LinkedListNode list, int x) {
      LinkedListNode head;
      //find first viable number
      for(head = list; null != head && head.val > x; head = head.next); 
      //find next viable number
      for (LinkedListNode current = head; null != current && null != current.next; ) {
        if (current.next.val > x) {
          current.next = current.next.next;
         } else {
          current = current.next;
         }
      }
      return head;
    }

3

    // Complete the maximumSum function below.
    static long maximumSum(List<Integer> arr) {
      if (arr.isEmpty()) {
        return 0;
      }
      long acc = 0, max = Integer.MIN_VALUE;
      for(int i=0; i < arr.size(); i++) {
          acc = Math.max(acc, 0); // ignore any negative accumulated sum
          acc += arr.get(i);
          max = Math.max(max, acc);
      }
      return max;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment