Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed src/problem1/.keep
Empty file.
24 changes: 24 additions & 0 deletions src/problem1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Time Complexity: O(1)
// Space Complexity: O(1)
function sum_to_n_a(n) {
return (n * (n + 1)) / 2;
};

// Time Complexity: O(n)
// Space Complexity: O(n)
function sum_to_n_b(n) {
return Array.from({ length: n }, (_, i) => i + 1).reduce((acc, curr) => acc + curr, 0);
};

// Time Complexity: O(n)
// Space Complexity: O(n)
function sum_to_n_c(n) {
if (n <= 0) return 0;
return n + sum_to_n_c(n - 1);
};

module.exports = {
sum_to_n_a,
sum_to_n_b,
sum_to_n_c,
};
27 changes: 27 additions & 0 deletions src/problem1/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const assert = require('assert');
const { sum_to_n_a, sum_to_n_b, sum_to_n_c } = require('./index');

function expectedSum(n) {
let sum = 0;
for (let i = 1; i <= n; i++) {
sum += i;
}
return sum;
}

// Test values (feel free to add more)
const testValues = [0, 1, 2, 5, 10, 100, 1000];

function runTests() {
testValues.forEach((n) => {
const expected = expectedSum(n);

assert.strictEqual(sum_to_n_a(n), expected, `sum_to_n_a failed for n=${n}`);
assert.strictEqual(sum_to_n_b(n), expected, `sum_to_n_b failed for n=${n}`);
assert.strictEqual(sum_to_n_c(n), expected, `sum_to_n_c failed for n=${n}`);
});

console.log('All tests passed!');
}

runTests();
24 changes: 24 additions & 0 deletions src/problem2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
16 changes: 16 additions & 0 deletions src/problem2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Token Swap Interface

A React-based cryptocurrency token swap interface built with TypeScript and Vite.

## Requirements

- Node.js 22+

## Development

```bash
npm run dev # Start dev server
npm run build # Build for production
npm run test # Run tests
npm run lint # Run linter
```
20 changes: 20 additions & 0 deletions src/problem2/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "tailwind.config.ts",
"css": "src/index.css",
"baseColor": "slate",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
}
}
23 changes: 23 additions & 0 deletions src/problem2/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
import { globalIgnores } from 'eslint/config'

export default tseslint.config([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
js.configs.recommended,
tseslint.configs.recommended,
reactHooks.configs['recommended-latest'],
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
},
])
38 changes: 12 additions & 26 deletions src/problem2/index.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
<html>

<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fancy Form</title>

<!-- You may add more stuff here -->
<link href="style.css" rel="stylesheet" />
</head>

<body>

<!-- You may reorganise the whole HTML, as long as your form achieves the same effect. -->
<form onsubmit="return !1">
<h5>Swap</h5>
<label for="input-amount">Amount to send</label>
<input id="input-amount" />

<label for="output-amount">Amount to receive</label>
<input id="output-amount" />

<button>CONFIRM SWAP</button>
</form>
<script src="script.js"></script>
</body>

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Fancy Form</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading