This file contains 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
const isPrime = (n) => { | |
if(n < 2) return false; | |
for(let i = 2; i <= Math.sqrt(n); i += 1) { | |
if(n % i === 0) { | |
return false; | |
} | |
} | |
return true; |
This file contains 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<int> rotLeft(List<int> a, int d) | |
{ | |
for (var i = 0; i < d; i++) | |
{ | |
var temp = a[0]; | |
a.RemoveAt(0); | |
a.Add(temp); | |
} | |
return a; | |
} |
This file contains 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 hourglassSum(List<List<int>> arr) | |
{ | |
var max = -63; // 7 * -9 lower value possible | |
for (var i = 0; i < 4; i++) { // 4 row possibilities | |
for (var j = 0; j < 4; j++) // 4 column possibilities | |
{ | |
var sum = 0; | |
sum = (arr[i][j] + arr[i][j + 1] + arr[i][j + 2] + arr[i + 1][j + 1] + arr[i + 2][j] + | |
arr[i + 2][j + 1] + arr[i + 2][j + 2]); | |
max = max < sum ? sum : max; |
This file contains 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 long repeatedString(string s, long n) | |
{ | |
if (string.IsNullOrEmpty(s) || n <= 0) return 0; | |
var c = 'a'; | |
long count = 0; | |
var repetitions = n / s.Length + 1; | |
var remainingSize = n % s.Length; | |
var i = 0; |
This file contains 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 jumpingOnClouds(List<int> c) | |
{ | |
var cloudPos = 0; | |
var jumpCount = 0; | |
var listSize = c.Count - 1; | |
while(true) { | |
if(cloudPos + 2 <= listSize && c[cloudPos + 2] == 0) | |
{ | |
cloudPos = cloudPos + 2; |
This file contains 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
using System.CodeDom.Compiler; | |
using System.Collections.Generic; | |
using System.Collections; | |
using System.ComponentModel; | |
using System.Diagnostics.CodeAnalysis; | |
using System.Globalization; | |
using System.IO; | |
using System.Linq; | |
using System.Reflection; | |
using System.Runtime.Serialization; |
This file contains 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
using System.CodeDom.Compiler; | |
using System.Collections.Generic; | |
using System.Collections; | |
using System.ComponentModel; | |
using System.Diagnostics.CodeAnalysis; | |
using System.Globalization; | |
using System.IO; | |
using System.Linq; | |
using System.Reflection; | |
using System.Runtime.Serialization; |