| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0312ee7 commit 0ae960c
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,7 @@ | |||
| 3 | 3 | * Find the maximum profit possible by cutting the rod and selling the pieces. | |
| 4 | 4 | */ | |
| 5 | 5 | ||
| 6 | - function rodCut(prices, n){ | ||
| 6 | + export function rodCut(prices, n){ | ||
| 7 | 7 | let memo = new Array(n + 1); | |
| 8 | 8 | memo[0] = 0; | |
| 9 | 9 | ||
@@ -18,10 +18,4 @@ | |||
| 18 | 18 | return memo[n]; | |
| 19 | 19 | } | |
| 20 | 20 | ||
| 21 | - function main(){ | ||
| 22 | - let arr = [1, 5, 4, 2, 1, 11, 19, 12]; | ||
| 23 | - let n = arr.length; | ||
| 24 | - console.log('Maximum Possible Profit is : '+ rodCut(arr,n)); | ||
| 25 | - } | ||
| 26 | - | ||
| 27 | - main(); | ||
| 21 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,22 @@ | |||
| 1 | + import { rodCut } from '../RodCutting' | ||
| 2 | + | ||
| 3 | + test('Test Case 1', () => { | ||
| 4 | + expect(rodCut([1,5,8,9,10,17,17,20],8)).toBe(22); | ||
| 5 | + }) | ||
| 6 | + | ||
| 7 | + test('Test Case 2', () => { | ||
| 8 | + expect(rodCut([1,5,4,2,1,11,19,12],8)).toBe(20); | ||
| 9 | + }) | ||
| 10 | + | ||
| 11 | + test('Test Case 3', () => { | ||
| 12 | + expect(rodCut([1,2,1],3)).toBe(3); | ||
| 13 | + }) | ||
| 14 | + | ||
| 15 | + test('Test Case 4', () => { | ||
| 16 | + expect(rodCut([5,4,3,2,1],5)).toBe(25); | ||
| 17 | + }) | ||
| 18 | + | ||
| 19 | + test('Test Case 5', () => { | ||
| 20 | + expect(rodCut([3,5,8,8,10,16,14,19],8)).toBe(24); | ||
| 21 | + }) | ||
| 22 | + | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments