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
var totalBribes = 0 | |
fun minimumBribes(arr: Array<Int>): Unit { | |
var currentPerson = 1 | |
var bribeArr = arr.clone() | |
var bribeMap = HashMap<Int, Int>().apply { | |
var index = 0 | |
bribeArr.forEach { | |
put(it, index++) | |
} |
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
fun prisonAfterNDays(cells: IntArray, N: Int): IntArray { | |
var currentIndex = 0 | |
val prisonMap = HashMap<List<Int>, Int>() | |
while (currentIndex < N) { | |
var tempArr = cells.clone() | |
if (prisonMap[tempArr.toList()]?.hashCode() != null) { | |
val cycleLength = currentIndex - prisonMap[tempArr.toList()]!! | |
val remainingDays = N - currentIndex |
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
// Complete the minimumSwaps function below. | |
fun minimumSwaps(arr: Array<Int>): Int { | |
var numberOfSwaps = 0 | |
val sortingMap: HashMap<Int, Int> = HashMap() | |
// Build hashing map, ex. | |
// [7, 1, 3, 2, 4, 5, 6] | |
// [0, 1, 2, 3, 4, 5, 6] | |
for (hashingIndex in 0 until arr.size) { | |
sortingMap[arr[hashingIndex]] = hashingIndex |
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
fun addTwoNumbers(l1: ListNode?, l2: ListNode?, nextNode: ListNode? = totalNode): ListNode? { | |
val firstVal = l1?.`val` ?: 0 | |
val secondVal = l2?.`val` ?: 0 | |
var total = firstVal + secondVal + (nextNode?.`val` ?: 0) | |
if (total >= 10) { | |
total = total.rem(10) | |
carryOn = 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
fun totalFruit(tree: IntArray): Int { | |
val collectedFruitSet = ArrayList<Int>() | |
var lastMax = 0 | |
for (loopingIndex in 0 until tree.size) { | |
if (tree.distinct().count() <= 2) { | |
lastMax = tree.size | |
break | |
} else if (collectedFruitSet.distinct().count() < 2 || ( | |
collectedFruitSet.distinct().count() == 2 && collectedFruitSet.contains(tree[loopingIndex]) |
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
public static List<String> removeSubfolders(String[] folders) { | |
HashSet<String> rootFoldersOnly = new HashSet<>(); | |
HashSet<String> setFolders = new HashSet<>(Arrays.asList(folders)); | |
for (String folder: folders) { | |
int searchIndex = 0; | |
int currentSegmentIndex = 1; | |
String matchingDirectory = ""; | |
String[] segments = folder.split("/"); |
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
public static int[] shiftNums(int[] nums, int shiftCount) { | |
int[] numsClone = nums.clone(); | |
while (shiftCount > 0) { | |
int itemToBeShifted = nums[nums.length - 1]; | |
for (int i = 0; i < nums.length - 1; i++) { | |
nums[i + 1] = numsClone[i]; | |
} |
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
public static ArrayList<List<String>> suggestedProducts(String[] products, String searchWord) { | |
ArrayList<List<String>> res = new ArrayList<>(); | |
List<String> sortedProducts = Arrays.asList(products); | |
Collections.sort(sortedProducts); | |
for (int charIndex = 1; charIndex <= searchWord.length(); charIndex++) { | |
String currentInput = searchWord.substring(0, charIndex); | |
ArrayList<String> subList = new ArrayList<>(); | |
int currentIndex = 0; | |
while (currentIndex < sortedProducts.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
server { | |
listen [::]:443 ssl; | |
listen 443 ssl; | |
server_name api.rostom.dev; | |
ssl_certificate /etc/letsencrypt/live/api.rostom.dev/fullchain.pem; # manag$ | |
ssl_certificate_key /etc/letsencrypt/live/api.rostom.dev/privkey.pem; # man$ | |
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot | |
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot | |
location / { |
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
fun main(vararg args: String) { | |
val nameSet: HashSet<String> = getUniqueListOfNames(listOf("Ahmed", "Ahmed", "Hassan", "Omar")) | |
println(validateHiring(nameSet, "Hamada")) | |
} | |
fun validateHiring(nameSet: HashSet<String>, searchingName: String): Boolean = !nameSet.contains(searchingName) | |
fun getUniqueListOfNames(listOfFullNames: List<String>): HashSet<String> { | |
val nameSet = HashSet<String>() |
OlderNewer