DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.

← Back to Questions
EasyJavaScript

The "Infinity Ledger" Addition Algorithm

1 views

In high-precision financial systems, such as central bank digital currencies (CBDC) or cross-border settlement layers, transaction volumes can often exceed the capacity of standard 64-bit floating-point numbers. In JavaScript, Number.MAX_SAFE_INTEGER is $2^{53} - 1$ (or 9,007,199,254,740,991).

Once a transaction total crosses this threshold, the engine loses precision, leading to "penny-drop" errors that can be catastrophic in a banking context. While modern environments support the BigInt type, many legacy systems or cross-language middleware require data to be handled as strings to ensure zero precision loss during serialization.


Problem Statement

You are tasked with building a core utility for a banking ledger. Implement a function bigAdd(a, b) that takes two non-negative integers represented as strings and returns their sum as a string.

Constraints & Requirements:

  • No Native BigInt: You may not use the BigInt() constructor or BigInt literals (e.g., 10n).

  • Arbitrary Length: The strings can be hundreds of characters long, far exceeding the limits of the Number type.

  • Non-negative: You only need to handle non-negative integers.

  • Efficiency: The solution should ideally run in $O(\max(N, M))$ time, where $N$ and $M$ are the lengths of the input strings.


Examples

Input a

Input b

Output

Logic

"999"

"1"

"1000"

Standard carry-over logic.

"9007199254740991"

"10"

"9007199254741001"

Exceeds MAX_SAFE_INTEGER.

"0"

"0"

"0"

Edge case: identity.

"12345678901234567890"

"98765432109876543210"

"111111111011111111100"

Extremely large values.


Sample Test Cases

Case 1
Input
a="999999999999999999", b="1"
Expected Output
"1000000000000000000"
Case 2
Input
a="0", b="0"
Expected Output
"0"
Case 3
Input
a="123", b="456"
Expected Output
"579"

No solutions yet

Be the first to share a solution for this question.

Comments (0)

Sign in to leave a comment.

No comments yet. Be the first to comment.

Stats

Views
1
Likes
0
Solutions
0
Comments
0

Category

Frontend Engineering

Languages

JavaScript