This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Suppose we have some input data describing a graph of relationships between parents and children over multiple generations. The data is formatted as a list of (parent, child) pairs, where each individual is assigned a unique positive integer identifier. | |
# For example, in this diagram, the earliest ancestor of 6 is 14, and the earliest ancestor of 15 is 2. | |
# 14 | |
# | | |
# 2 4 | |
# | / | \ | |
# 3 5 8 9 | |
# / \ / \ \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node(): | |
def __init__(self, val): | |
self.val = val | |
self.left = None | |
self.right = None | |
T = Node(0) | |
T.left = Node(1) | |
T.right = Node(-2) | |
T.left.right = Node(2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Let's define a sevenish number is a number that is one of a power of 7, or a number that is the sum of unique power of 7s | |
From the beginning the first few sevenish are: | |
1, 7, 8, 49, 50 and so on | |
You are to create an algorithm that finds the i'th sevenish number | |
''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Given a sequence of positive integers in a string, and a positive integer k between 2 and n where n is the number of positive integers in the given string, | |
Return the string that is a size k sequence of the given string that represents the largest number. | |
Example: | |
Input: '85888900', 3 | |
Output: '900' | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.spark.sql.*; | |
/** | |
* Parses a line of a fixed width flat file | |
* @param pos list of integers describing the width of each column of the flat file | |
* @param str line of the fixed width flat file | |
* @return Row containing data from fixed width flat file line | |
*/ | |
public static Row lSplit(List<Integer> pos, String str) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks if all the lists representing the values of a hashmap are the same length. | |
* @param occurrenceFields a hashmap with strings as the keys and lists of strings as the values | |
* @return true if all the lists are the same length, false otherwise | |
*/ | |
private static boolean checkLengths(HashMap<String, HashMap<String, String>> occurrenceFields) { | |
Set<Integer> sizes = new HashSet<Integer>(); | |
for (HashMap<String, String> list : occurrenceFields.values()) { | |
sizes.add(list.size()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Question 1: Delete an item in a linked list */ | |
#include <bits/stdc++.h> | |
typedef struct list_item { | |
int value; | |
list_item* next; | |
} list_item; | |
// Iterates through the items in the linked list and checks for the specified |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <sunmatrix/sunmatrix_dense.h> // access to dense SUNMatrix | |
#include <sunmatrix/sunmatrix_sparse.h> // access to sparse SUNMatrix | |
// Converts 2d vector into a sparse matrix. This function assumes all the rows | |
// are the same size. | |
SUNMatrix convert_to_sparse(std::vector< std::vector< realtype > > vec) { | |
// Defining the rows and columns. | |
SUNMatrix temp_dense = SUNDenseMatrix(vec.size(), vec[0].size()); |