Skip to content

Instantly share code, notes, and snippets.

View neilharia7's full-sized avatar
:octocat:

Neil Haria neilharia7

:octocat:
View GitHub Profile
import random
def isPrime(num):
if num == 2: return True
if num < 2 or num % 2 == 0: return False
for i in range(3, int(num ** 0.5) + 2, 2):
if num % i == 0: return False
return True
def gcd(e, phi): return e if phi == 0 else gcd(phi, e % phi)
/*
Input Format. Input contains one string 𝑆 which consists of big and small latin letters, digits, punctuation
marks and brackets from the set []{}().
Constraints. The length of 𝑆 is at least 1 and atmost 10^5.
Output Format. If the code in 𝑆 uses brackets correctly, output “Success" (without the quotes). Otherwise,
output the 1-based index of the first unmatched closing bracket, and if there are no unmatched closing
brackets, output the 1-based index of the first unmatched opening bracket.
*/
@neilharia7
neilharia7 / DijkstrasAlgorithm.java
Last active February 10, 2017 18:31
Dijkstra's shortest path code in java which gives shortest route to all other paths
/*
Dijkstra's Shortest Path Algorithm
The following program gives the shortest path from the source to all other nodes
*/
import java.util.*;
import java.io.*;
class DijkstrasAlgorithm{
public static void main(String args[]){
int array[][];
int i,j,n,s;