Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9180713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:07:13+00:00 2026-06-17T18:07:13+00:00

I came across a task which makes you check if a String passed as

  • 0

I came across a task which makes you check if a String passed as an argument to your method/function is a correct statement in the Reverse Polish Notation sense. It can contain lowercase alphabet letters, operation signs and integers. Is there any faster way to check it than to read every character separately and actually try to evaluate the whole expression?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:07:14+00:00Added an answer on June 17, 2026 at 6:07 pm

    You don’t have to evaluate the whole expression but you do need to split it into tokens, and you have to know the valence of every operator (that is, how many operands it takes). For simplicity, let the valence of an operand be 0; then do the following:

    Set stack_size to 0;
    For Each token In expression:
        Set stack_size to stack_size + 1 - valence(token)
        If stack_size <= 0: Report failure
    If stack_size == 1: Report success
    Else              : Report failure
    

    Examples using _ for unary minus.

    expression:     3 4 + 1 * _
    stack_size:   0 1 2 1 2 1 1 -> success
    
    expression:     2 3 4 + 1 * _
    stack_size:   0 1 2 3 2 3 2 2 -> failure (not 1 at the end)
    
    expression:     2 3 + + 1 * _
    stack_size:   0 1 2 1 0       -> failure (stack_size <= 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across a piece of code which looks like this: jQuery(function($) { $('#saySomething').click(function()
I came across a Sanity Check sql task in an old DTS Package, but
I'm working on Eclipse ADT. I came across task where I need to check
I came across the task to find all occurences of a substring in another
While I was working on a small task I came across a situation DECLARE
I came across code to stop execution's task. private final ExecutorService executor = Executors.newSingleThreadExecutor();
I have recently started working on phonegap and i came across a task in
Came across a code, and was wondering why this works? $.fn.appendVal = function(txt) {
Came across a problem which google searches could not help me with. I have
I am building a WP7 application which heavily uses RX and I came across

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.