-
Notifications
You must be signed in to change notification settings - Fork 24
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
Showing
15 changed files
with
357 additions
and
8 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
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
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
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
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 @@ | ||
# Algorithms > Search > Sherlock and Array | ||
# Check whether there exists an element in the array such that sum of elements on its left is equal to the sum of elements on its right. | ||
# | ||
# https://www.hackerrank.com/challenges/sherlock-and-array/problem | ||
# https://www.hackerrank.com/contests/101may14/challenges/sherlock-and-array | ||
# challenge id: 2490 | ||
# | ||
|
||
|
||
def solve(a): | ||
i = 0 | ||
j = len(a) - 1 | ||
l = r = 0 | ||
|
||
while i < j: | ||
if l < r: | ||
l += a[i] | ||
i += 1 | ||
else: | ||
r += a[j] | ||
j -= 1 | ||
|
||
return "YES" if l == r else "NO" | ||
|
||
|
||
for _ in range(int(input())): | ||
n = int(input()) | ||
a = list(map(int, input().split())) | ||
result = solve(a) | ||
print(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
Binary file not shown.
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
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
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 @@ | ||
// Tutorials > 10 Days of Javascript > Day 4: Classes | ||
// Practice using JavaScript classes. | ||
// | ||
// https://www.hackerrank.com/challenges/js10-class/problem | ||
// challenge id: 21855 | ||
// | ||
|
||
/* | ||
* Implement a Polygon class with the following properties: | ||
* 1. A constructor that takes an array of integer side lengths. | ||
* 2. A 'perimeter' method that returns the sum of the Polygon's side lengths. | ||
*/ | ||
class Polygon { | ||
constructor(sides) { | ||
this.sides = sides; | ||
} | ||
|
||
perimeter() | ||
{ | ||
let sum = 0; | ||
for (const s of this.sides) | ||
sum += s; | ||
return sum; | ||
} | ||
} | ||
|
||
// (skeliton_tail) ---------------------------------------------------------------------- | ||
const rectangle = new Polygon([10, 20, 10, 20]); | ||
const square = new Polygon([10, 10, 10, 10]); | ||
const pentagon = new Polygon([10, 20, 30, 40, 43]); | ||
|
||
console.log(rectangle.perimeter()); | ||
console.log(square.perimeter()); | ||
console.log(pentagon.perimeter()); |
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,60 @@ | ||
// Tutorials > 10 Days of Javascript > Day 4: Count Objects | ||
// Iterate over the elements in an array and perform an action based on each element's properties. | ||
// | ||
// https://www.hackerrank.com/challenges/js10-count-objects/problem | ||
// challenge id: 21013 | ||
// | ||
|
||
'use strict'; | ||
|
||
process.stdin.resume(); | ||
process.stdin.setEncoding('utf-8'); | ||
|
||
let inputString = ''; | ||
let currentLine = 0; | ||
|
||
process.stdin.on('data', inputStdin => { | ||
inputString += inputStdin; | ||
}); | ||
|
||
process.stdin.on('end', _ => { | ||
inputString = inputString.trim().split('\n').map(string => { | ||
return string.trim(); | ||
}); | ||
|
||
main(); | ||
}); | ||
|
||
function readLine() { | ||
return inputString[currentLine++]; | ||
} | ||
// (skeliton_head) ---------------------------------------------------------------------- | ||
|
||
/* | ||
* Return a count of the total number of objects 'o' satisfying o.x == o.y. | ||
* | ||
* Parameter(s): | ||
* objects: an array of objects with integer properties 'x' and 'y' | ||
*/ | ||
function getCount(objects) { | ||
|
||
var count = 0; | ||
for (const o of objects) | ||
if (o.x == o.y) count++; | ||
|
||
return count; | ||
} | ||
|
||
// (skeliton_tail) ---------------------------------------------------------------------- | ||
function main() { | ||
const n = +(readLine()); | ||
let objects = []; | ||
|
||
for (let i = 0; i < n; i++) { | ||
const [a, b] = readLine().split(' '); | ||
|
||
objects.push({x: +(a), y: +(b)}); | ||
} | ||
|
||
console.log(getCount(objects)); | ||
} |
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,57 @@ | ||
// Tutorials > 10 Days of Javascript > Day 4: Create a Rectangle Object | ||
// Create an object with certain properties in JavaScript. | ||
// | ||
// https://www.hackerrank.com/challenges/js10-objects/problem | ||
// challenge id: 21012 | ||
// | ||
|
||
'use strict'; | ||
|
||
process.stdin.resume(); | ||
process.stdin.setEncoding('utf-8'); | ||
|
||
let inputString = ''; | ||
let currentLine = 0; | ||
|
||
process.stdin.on('data', inputStdin => { | ||
inputString += inputStdin; | ||
}); | ||
|
||
process.stdin.on('end', _ => { | ||
inputString = inputString.trim().split('\n').map(string => { | ||
return string.trim(); | ||
}); | ||
|
||
main(); | ||
}); | ||
|
||
function readLine() { | ||
return inputString[currentLine++]; | ||
} | ||
// (skeliton_head) ---------------------------------------------------------------------- | ||
|
||
/* | ||
* Complete the Rectangle function | ||
*/ | ||
function Rectangle(a, b) { | ||
|
||
return { | ||
length: a, | ||
width: b, | ||
perimeter: (a + b) * 2, | ||
area: a * b | ||
}; | ||
} | ||
|
||
// (skeliton_tail) ---------------------------------------------------------------------- | ||
function main() { | ||
const a = +(readLine()); | ||
const b = +(readLine()); | ||
|
||
const rec = new Rectangle(a, b); | ||
|
||
console.log(rec.length); | ||
console.log(rec.width); | ||
console.log(rec.perimeter); | ||
console.log(rec.area); | ||
} |
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,59 @@ | ||
// Tutorials > 10 Days of Javascript > Day 3: Throw | ||
// Practice throwing errors` in JavaScript. | ||
// | ||
// https://www.hackerrank.com/challenges/js10-throw/problem | ||
// challenge id: 20998 | ||
// | ||
|
||
'use strict'; | ||
|
||
process.stdin.resume(); | ||
process.stdin.setEncoding('utf-8'); | ||
|
||
let inputString = ''; | ||
let currentLine = 0; | ||
|
||
process.stdin.on('data', inputStdin => { | ||
inputString += inputStdin; | ||
}); | ||
|
||
process.stdin.on('end', _ => { | ||
inputString = inputString.trim().split('\n').map(string => { | ||
return string.trim(); | ||
}); | ||
|
||
main(); | ||
}); | ||
|
||
function readLine() { | ||
return inputString[currentLine++]; | ||
} | ||
// (skeliton_head) ---------------------------------------------------------------------- | ||
|
||
/* | ||
* Complete the isPositive function. | ||
* If 'a' is positive, return "YES". | ||
* If 'a' is 0, throw an Error with the message "Zero Error" | ||
* If 'a' is negative, throw an Error with the message "Negative Error" | ||
*/ | ||
function isPositive(a) { | ||
|
||
if (a == 0) throw Error("Zero Error"); | ||
if (a < 0) throw Error("Negative Error"); | ||
return "YES"; | ||
} | ||
|
||
// (skeliton_tail) ---------------------------------------------------------------------- | ||
function main() { | ||
const n = +(readLine()); | ||
|
||
for (let i = 0; i < n; i++) { | ||
const a = +(readLine()); | ||
|
||
try { | ||
console.log(isPositive(a)); | ||
} catch (e) { | ||
console.log(e.message); | ||
} | ||
} | ||
} |
Oops, something went wrong.