Coder Social home page Coder Social logo

github-externship-assignment's Introduction

Github Externship Assignment

Problem statement

You are given a String equation containing an equation of the form A * B + C = D, where A, B, C and D are positive integers that don't have leading zeros.
One digit in the equation is missing.
Determine and return the correct digit.
If the missing digit cannot be determined (i.e., there is no solution or there is more than one solution), return -1 instead.

Definition

  • Class: FixEquation
  • Method : findMissingDigit
  • Parameters : String
  • Returns : Integer
  • Method signature : function findMissingDigit(equation)

Note: A digit is correct if and only if it produces a valid equation in which A, B, C and D are positive integers with no leading zeros.

Constraints

  • Equation will have the form A * B + C = D.
  • Each of A, B, C, D will be a nonempty string of 1 to 4 characters, i.e., 1 <= length of A, B, C, D <= 4.
  • Each character in each of A, B, C, D will be either a digit ('0'-'9') or a question mark ('?').
  • There will be exactly one question mark in equation.
  • The numbers represented by A, B, C, D will not have leading zeros.

Test Cases

1️⃣

Equation: 42 * 47 + 2 = 1?76

Returns: 9

We know that 42 * 47 + 2 = 1974, so the missing digit is 9.

2️⃣

Equation: 4? * 47 + 2 = 1976

Returns: 2

The same equation, another missing digit.

3️⃣

Equation: 42 * ?7 + 2 = 1976

Returns: 4

And again the same equation.

4️⃣

Equation: 42 * ?47 + 2 = 1976

Returns: -1

This test case has no valid solution. The numbers cannot have leading zeros, so we cannot fill in a zero in front of 47.

5️⃣

Equation: 2 * 12? + 2 = 247

Returns: -1

Two times something + 2 will never be 247, so this test case has no solution either.

github-externship-assignment's People

Contributors

sooditk avatar mayur-rammer avatar visharma-symbl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.