Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add solution for the externship task #177

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aguyran
Copy link

@aguyran aguyran commented Dec 19, 2021

  • Externship Task Completed
  • All Tasks Passed

Approach

  • Iterated over the equation and maintained character into a temporary variable token to keep track of current digits or symbols and pushed it to an array called split whenever empty space encountered(" ").
  • whenever question mark encountered it can be said it is at the number at split array length as indexing is from 0 but length is total no. of elements so store it in positionOfQues
  • Now we have 4 equations, ex if question mark is there in first number (D-C/B)=?
  • Use the correct equation according to the positionOfQues, and use eval to solve it
  • if there would be a 0 at left it would be automatically removed because its a number so we just check the length of answer with original, if they don't match 0 was on the left side or answer was not possible.
  • Now if lengths match we check all the digits of the question with Answer minus the digit at ? if it matches we return position of question mark in answer otherwise -1
  • Map to check test cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant