-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4af6cd2
Showing
22 changed files
with
614 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Given an array of integers, find how many times minimum number comes and maximum number comes. | ||
// variables defined by var are available throughout the function in which they are declared, let are onoly available inside the block they are defined | ||
|
||
|
||
let arr = [12,24,10,24] | ||
|
||
console.log(breakingRecords(arr)); | ||
function breakingRecords(scores) { | ||
// Write your code here | ||
let max=scores[0]; | ||
let min=scores[0]; | ||
let countMax=0; | ||
let countMin=0 | ||
for (let ele of scores){ | ||
if (ele<min){ | ||
min=ele; | ||
countMin++; | ||
}if (ele>max){ | ||
max=ele; | ||
countMax++; | ||
} | ||
} | ||
return [countMax,countMin]; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
function breakingRecords(scores) { | ||
let most = scores[0], | ||
least = scores[0], | ||
countmax = 0, | ||
countmin = 0; | ||
for (const element of scores){ | ||
if (element<least){ | ||
least = element; | ||
countmin++; | ||
} | ||
if (element>most){ | ||
most = element; | ||
countmax++; | ||
} | ||
} | ||
return [countmax, countmin] | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import math\n", | ||
"import os\n", | ||
"import random\n", | ||
"import re\n", | ||
"\n", | ||
"\n", | ||
"def breakingRecords(scores):\n", | ||
" most, least = scores[0], scores[0]\n", | ||
" countmax, countmin = 0, 0\n", | ||
" for i in scores:\n", | ||
" if i<least:\n", | ||
" least = i\n", | ||
" countmin+=1\n", | ||
" if i>most:\n", | ||
" most = i\n", | ||
" countmax+=1\n", | ||
" return [countmax,countmin]\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import math\n", | ||
"import os\n", | ||
"import random\n", | ||
"import re\n", | ||
"import sys\n", | ||
"\n", | ||
"def divisibleSumPairs(n, k, ar):\n", | ||
" count = 0\n", | ||
" for i in range(n):\n", | ||
" for j in range(i+1,n):\n", | ||
" if i < j and (ar[i] + ar[j])%k ==0:\n", | ||
" count+=1\n", | ||
" return count\n", | ||
"\n", | ||
" fptr.close()\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// input arr, k and n. find divisble by k. sum of arr[i] and arr[j]. divide by k. when i<j | ||
|
||
let arr = [1,3,2,6,1,2]; | ||
let k = 3 | ||
|
||
let n = arr.length; | ||
|
||
console.log(divisibleSumPairs(n,k,arr)) | ||
|
||
function divisibleSumPairs(n,k,arr){ | ||
let count=0; | ||
for (let i=0;i<n;i++){ | ||
for (let j=0;j<n;j++){ | ||
if (i<j){ | ||
let div = (arr[i]+arr[j])%k; | ||
if (div==0){ count++; } | ||
} | ||
} | ||
} | ||
return count; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
def matchingStrings(strings, queries): | ||
result=[] | ||
for i in range(len(queries)): | ||
count=0 | ||
for j in range(len(strings)): | ||
if queries[i]==strings[j]: | ||
count+=1 | ||
result.append(count) | ||
return result | ||
|
||
def matchingStringsNew(strings, queries): | ||
s = Counter(strings) | ||
result = [] | ||
for q in queries: | ||
result.append(s[q]) | ||
return result |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Given an array, find biggest and smallest number of the sum of arrays | ||
|
||
let arr = [5,5,5,5,5] | ||
minmax(arr) | ||
function minmax(arr){ | ||
let tempArr=[] | ||
for (let i=0;i<arr.length;i++){ | ||
let sum=0 | ||
for (let j=0;j<arr.length;j++){ | ||
if (i==j){continue;} | ||
sum=sum+arr[j] | ||
} | ||
tempArr.push(sum) | ||
} | ||
|
||
console.log(findRes(tempArr)); | ||
} | ||
function findRes(arr){ | ||
// This func returns smallest and largest values in an array | ||
let max=arr[0] | ||
let min=arr[0] | ||
for (let i=0;i<arr.length;i++){ | ||
if (arr[i]>max){ | ||
max = arr[i] | ||
}if (arr[i]<min){ | ||
min = arr[i] | ||
} | ||
} | ||
return min+' '+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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import math | ||
import os | ||
import random | ||
import re | ||
import sys | ||
|
||
|
||
def miniMaxSum(arr): | ||
# Write your code here | ||
print(sum(arr) - max(arr), sum(arr) - min(arr)) | ||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def miniMaxSum(arr):\n", | ||
" # Write your code here\n", | ||
" print(sum(arr) - max(arr), sum(arr) - min(arr))" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Given an array of positive,negative and zero. return count of pos,neg and zero divided by length of array | ||
|
||
function plusMinus(arr) { | ||
// Write your code here | ||
var pos=0 | ||
var neg=0 | ||
var zero=0 | ||
//let arr = [1,1,0,-1,-1] | ||
let len = arr.length | ||
for (let i=0;i<len;i++){ | ||
if (arr[i]<0){ | ||
neg=neg+1 | ||
}else if (arr[i]>0){ | ||
pos=pos+1 | ||
}else if (arr[i]==0){ | ||
zero=zero+1 | ||
} | ||
} | ||
var resPos=pos/len; | ||
var resNeg=neg/len; | ||
var resZero=zero/len; | ||
console.log(resPos.toFixed(6)); | ||
console.log(resNeg.toFixed(6)); | ||
console.log(resZero.toFixed(6)); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import math\n", | ||
"import os\n", | ||
"import random\n", | ||
"import re\n", | ||
"import sys\n", | ||
"\n", | ||
"\n", | ||
"def plusMinus(arr):\n", | ||
" # Write your code here\n", | ||
" p = n = z =0\n", | ||
" \n", | ||
" for i in arr:\n", | ||
" p += i >0\n", | ||
" n += i<0\n", | ||
" z += i==0 \n", | ||
" l = len(arr)\n", | ||
" \n", | ||
" print(round(p/l,6))\n", | ||
" print(round(n/l,6))\n", | ||
" print(round(z/l,6))" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// input-> 12 Hr format. Output-> 24 Hr format | ||
|
||
let time = '12:45:54PM' | ||
|
||
timeConversion(time); | ||
|
||
function timeConversion(s){ | ||
var result='' | ||
var HH=s.slice(0,2); | ||
var slot=s.slice(-2); // AM / PM | ||
// console.log(HH+' '+slot); | ||
var res='' | ||
if (slot=='AM'){ | ||
if (parseInt(HH)==12){ | ||
res='00'; | ||
var result = replaceChar(s,res,2); | ||
} | ||
else if (parseInt(HH)<12){ | ||
var result = s.substr(0,(s.length-2)) | ||
} | ||
}else if(slot=='PM'){ | ||
if (parseInt(HH)<12){ | ||
res=parseInt(HH)+12 | ||
var result = replaceChar(s,res,2); | ||
}else if (parseInt(HH)==12){ | ||
var result = s.substr(0,(s.length-2)) | ||
} | ||
} | ||
console.log(result); | ||
return result; | ||
} | ||
|
||
//replaceChar('01:01:22AM','00',2) | ||
function replaceChar(str,repStr,i){ | ||
let len=str.length | ||
let firstStr=str.substr(0,i) | ||
let lastStr=str.substr(i,len-4); | ||
//console.log(repStr+lastStr) | ||
return repStr+lastStr | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import math\n", | ||
"import os\n", | ||
"import random\n", | ||
"import re\n", | ||
"import sys\n", | ||
"\n", | ||
"\n", | ||
"def timeConversion(s):\n", | ||
" time = s[:8]\n", | ||
" am_pm = s[8:]\n", | ||
" h, m, s = time.split(\":\")\n", | ||
" h = int(h)\n", | ||
" if am_pm == 'PM':\n", | ||
" if h!=12:\n", | ||
" h+=12\n", | ||
" return f'{h}:{m}:{s}'\n", | ||
" else:\n", | ||
" if h==12:\n", | ||
" h=00\n", | ||
" h = '0' + str(h)\n", | ||
" return f'{h}:{m}:{s}'\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.