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 java.util.*; | |
class ValueWithCount { | |
int value; | |
int index; | |
ValueWithCount(int value, int index) { | |
this.value = value; | |
this.index = 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
N1, N2 = [int(v) for v in input().split()][:2] | |
if N1 == N2 or abs(N1-N2) == 1: | |
print("p2") | |
else: | |
print("p1") | |
# More Explaination | |
# ---------------------------------- | |
# 2 2 --- two piles p1 takes a first turn |
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
def findFourElements(arr, N, K): | |
arr.sort() | |
for i in range(N - 3): | |
if i > 0 and arr[i] == arr[i-1]: | |
continue | |
for j in range(i+1, N - 2): | |
if j > i+1 and arr[j] == arr[j - 1]: | |
continue | |
l = j+1 | |
r = N - 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
#include <iostream> | |
#include <bits/stdc++.h> | |
using namespace std; | |
int getSum(int arr[],int N, int K) { | |
for(int i=0; i < N; i++){ | |
if(i > 0 && arr[i] == arr[i+1]) { | |
continue; | |
} | |
for(int j=i+1; j<N; j++) { |
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 java.util.*; | |
class Pair { | |
int first; | |
int second; | |
public Pair(int first, int second) { | |
this.first = first; | |
this.second = second; | |
} |
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 Node { | |
int data; | |
Node next; | |
Node(int data) { | |
this.data = data; | |
this.next = null; | |
} | |
} | |
class Main { |
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
#include <iostream> | |
using namespace std; | |
int main() { | |
int N; | |
cin >> N; // Number if values | |
int value; | |
int count = 0 ; | |
for(int i = 0; i < N; 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
# This problem can be solved using split() and join() | |
def reverse_words(sen): | |
words = sen.split(' ') # split sentence into words | |
# then reverse a list of words and join them as a sentence | |
string = ' '.join(reversed(words)) | |
print(string) | |
sen = "python is love" |
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
# program to find lenght of longest substring without repeating characters. | |
def findLongestSubstring(string): | |
l = len(string) | |
st = 0 # starting point of current substring. | |
maxlen = 0 # maximum length of substring | |
start = 0 # starting index of maximum | |
d = dict() # dictionary to store last occurrence |
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 is a easy problem you know how rotation works. | |
# this problem can be sloved using index() | |
def check_rotation(string1, string2): | |
if len(string1) != len(string2): # check for base case | |
return "No" | |
con = string1*2 # concatenate string with itself | |
if con.count(string2) > 0: # check for string2 in concatenated string | |
return "Yes" |
NewerOlder