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.scalatest.{Matchers, WordSpec} | |
import scala.annotation.tailrec | |
/** | |
* Assume you have a method isSubstring which checks if one word is a substring of another. | |
* Given two strings, 51 and 52, write code to check if 52 is a rotation of 51 using only | |
* one call to isSubstring (e.g.,"waterbottle"is a rotation of"erbottlewat"). | |
* Time Complexity: O(n) | |
* Created by Arun Sethia on 7/7/18. |
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.scalatest.{Matchers, FunSpec, WordSpec} | |
import scala.util.Try | |
/** | |
* Given an image represented by an NxN matrix, | |
* write a method to rotate the by 90 degrees. | |
* do this in place. | |
* Time Complexity O(n*n) | |
* Created by Arun Sethia on 7/8/18. |
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
package linkedlist | |
import scala.annotation.tailrec | |
import scala.collection.immutable.HashMap | |
/** | |
* LinkList remove duplicates using HashMap | |
* Time Complexity O(n) | |
* Space Complexity O(n) for hashmap if all are duplicates |
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.scalatest.{Matchers, WordSpec} | |
/** | |
* Implement an algorithm to find the kth to last element of a singly linked list. | |
* time complexity O(n) | |
* space complexity O(1) | |
* Created by Arun Sethia on 7/17/18. | |
*/ | |
trait Linklist { |
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.scalatest.{Matchers, WordSpec} | |
/** | |
* Implement an algorithm to find the middle element of a singly linked list. | |
* time complexity O(n) | |
* space complexity O(1) | |
* Created by Arun Sethia on 7/17/18. | |
*/ | |
trait Linklist { |
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.scalatest.{Matchers, WordSpec} | |
/** | |
* Implement an algorithm to remove the middle element of a singly linked list. | |
* and return new linklist | |
* time complexity O(n) | |
* space complexity O(n/2) | |
* Created by Arun Sethia on 7/17/18. | |
*/ | |
trait Linklist { |
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.scalatest.{Matchers, WordSpec} | |
import scala.annotation.tailrec | |
/** | |
* You have two numbers represented by a linked list, where each node contains a single digit. | |
* The digits are stored in reverse order, such that the 1's digit is at the head of the list. | |
* Write a function that adds the two numbers and returns the sum as a linked list. | |
* | |
* Assumptions: both list has equal number of nodes |
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.scalatest.WordSpec | |
import scala.annotation.tailrec | |
/** | |
* Given a circular linked list, implement an algorithm that returns if loop exist | |
* | |
* Time Complexity O(n) and Space Complexity zero | |
* | |
* Created by Arun Sethia on 7/23/18. |
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 scala.annotation.tailrec | |
/** | |
* Given a circular linked list, implement an algorithm that returns | |
* the node at the beginning of the loop. | |
* | |
* Time Complexity O(n) and Space Complexity O(n) | |
* | |
* Created by Arun Sethia on 7/23/18. | |
*/ |
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
package linklist4 | |
import scala.annotation.tailrec | |
/** | |
* Given a circular linked list, implement an algorithm that returns | |
* the node at the beginning of the loop. | |
* | |
* Time Complexity O(n+m) and Space Complexity O(n) | |
* |