A small TypeScript project that implements a merge function for three integer collections and includes unit tests using Jest.
- Node.js (v18 or later recommended)
- npm
Install project dependencies:
npm installExecute the sample program:
npm run startExecute all unit tests:
npm testmerge-project/
├── src/
│ └── index.ts # Merge implementation
├── tests/
│ └── merge.test.ts # Unit tests
├── jest.config.js # Jest + ts-jest configuration
├── package.json # Scripts and dependencies
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation
The solution takes advantage of the input constraints:
collection1is sorted in ascending order.collection2is sorted in descending order.collection3is sorted in ascending order.
Instead of sorting all values again, the implementation:
- Merges
collection1withcollection2by traversingcollection2from the end. - Merges the intermediate result with
collection3.
No built-in sorting function (such as Array.prototype.sort) is used.
- Time Complexity:
O(n1 + n2 + n3) - Space Complexity:
O(n1 + n2 + n3)