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 LinkedList { | |
private var head: Node? = null | |
private var tail: Node? = null | |
private var size = 0 | |
fun isEmpty(): Boolean { | |
return size == 0 | |
} | |
/** Adding a value at the front of the list. */ |
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
/** Removing a value at the front of the list. */ | |
fun pop() { | |
if (!isEmpty()) size-- | |
head = head?.next | |
if (isEmpty()) { | |
tail = null | |
} | |
} |
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
/** Adding a value at the front of the list. */ | |
fun push(value: String) { | |
head = Node(value = value, next = head) | |
if (tail == null) { | |
tail = head | |
} | |
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
class LinkedList { | |
private var head: Node? = null | |
private var tail: Node? = null | |
private var size = 0 | |
fun isEmpty(): Boolean { | |
return size == 0 | |
} | |
} |
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
data class Node(var value: String, var next: Node? = null) |
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
struct node { | |
int value; | |
struct node *next; | |
}; |
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
/** | |
* This question is asked by Apple. Given two binary strings (strings containing only 1s and 0s) return their sum (also as a binary string). | |
* Note: neither binary string will contain leading 0s unless the string itself is 0. | |
* Ex: Given the following binary strings... | |
* | |
* "100" + "1", return "101" | |
* "11" + "1", return "100" | |
* "1" + "0", return "1" | |
* | |
*/ |
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
/** | |
* This question is asked by Google. Given a string, return whether or not it uses capitalization correctly. | |
* A string correctly uses capitalization if all letters are capitalized, no letters are capitalized, or only the first letter is capitalized. | |
* Ex: Given the following strings... | |
* | |
* "USA", return true | |
* "Calvin", return true | |
* "compUter", return false | |
* "coding", return true | |
* |
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
/** | |
* This question is asked by Facebook. Given a string, return whether or not it forms a | |
* palindrome ignoring case and non-alphabetical characters. | |
* | |
* Note: a palindrome is a sequence of characters that reads the same forwards and backwards. | |
* | |
* Ex: Given the following strings... | |
* "level", return true | |
* "algorithm", return false | |
* "A man, a plan, a canal: Panama.", return true |
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
/** | |
* This question is asked by Google. Given a string, reverse all of its characters and return the resulting string. | |
* Ex: Given the following strings... | |
* “Cat”, return “taC” | |
* “The Daily Byte”, return "etyB yliaD ehT” | |
* “civic”, return “civic” | |
*/ | |
fun main() { | |
val stringValue = readLine()!! |