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
if __name__ == '__main__': | |
n = int(input()) | |
arr = map(int, input().split()) | |
print(sorted(set(arr))[-2]) |
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
if __name__ == '__main__': | |
nestedList = [] | |
for _ in range(int(input())): | |
name = input() | |
score = float(input()) | |
nestedList.append([name,score]) | |
#print(nestedList, name, score) | |
#sort the nested list based on the second digit | |
nestedList.sort(key = lambda x:x[1]) | |
#print(nestedList) |
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
int lengthOfLongestSubstring(char* s) { | |
int len = strlen(s); | |
int i=0,count=0,max=0; | |
for(i=0;i<len;i++) | |
{ | |
int arr[256]={0}; | |
count=0; | |
int j=0; | |
for(j=i;j<len;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
/** | |
* Definition for singly-linked list. | |
* type ListNode struct { | |
* Val int | |
* Next *ListNode | |
* } | |
*/ | |
func Push(lst *ListNode, x int) *ListNode{ | |
temp := &ListNode{Val:x,Next:nil} | |
if lst == nil { |
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
func twoSum(nums []int, target int) []int { | |
data :=make(map[int]int,0) | |
returnData := make([]int,0) | |
for i:=0;i< len(nums);i++{ | |
if val,found := data[target-nums[i]];found{ | |
returnData = append(returnData, val, i) | |
break | |
}else{ | |
data[nums[i]] =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
func deleteNode(llist *SinglyLinkedListNode, position int32) *SinglyLinkedListNode { | |
// Write your code here | |
var count int32 | |
head := llist | |
if head == nil { | |
return llist | |
} | |
if position == 0{ | |
return llist.next | |
} |
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
func plusOne(digits []int) []int { | |
length := len(digits)-1 | |
var remain int | |
firstSum := true | |
for j:= length;j>=0;j--{ | |
var sum int | |
if firstSum { | |
sum = digits[j]+1 | |
firstSum = false | |
}else{ |
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
//anagram used to check | |
//hackerank solution: https://www.hackerrank.com/challenges/anagram/problem | |
func anagram(s string) int32 { | |
if len(s)%2 != 0 { | |
return -1 | |
} | |
runeMap := make(map[rune]int,0) | |
runesWord := []rune(s) | |
//fmt.Printf("Runes: %v:%d:%d\n", runesWord,(len(runesWord)-1)/2,((len(runesWord)-1)/2)+1) | |
for i:=0;i<=(len(runesWord)-1)/2;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
import( | |
"strings" | |
"fmt" | |
) | |
func lengthOfLastWord(s string) int { | |
str := strings.Split(s," ") | |
for j:= len(str)-1;j>=0;j--{ | |
if str[j] == ""{ | |
continue |