Solved

parentbit challenge

Posted on 2016-09-21
3
112 Views
Last Modified: 2016-09-22
Hi,

I am going through below challenge

Recursion-1 > parenBit
prev  |  next  |  chance
Given a string that contains a single pair of parenthesis, compute recursively a new string made of only of the parenthesis and their contents, so "xyz(abc)123" yields "(abc)".

parenBit("xyz(abc)123") → "(abc)"
parenBit("x(hello)") → "(hello)"
parenBit("(xy)1") → "(xy)"
i have not understood the description. please advise
0
Comment
Question by:gudii9
  • 2
3 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 41810242
>> i have not understood the description.
What don't you understand?

Given a string containing '(' and ')', you have to strip off everything before the '(' and after the ')'.
0
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 41810256
Consider this:
public String parenBit(String str) {
  if (str.startsWith("(")) {
     return "(" + str.substring(1, str.indexOf(")")+1);
  }
  return parenBit(str.substring(1));
}

Open in new window

0
 
LVL 7

Author Comment

by:gudii9
ID: 41810896
i missed the link

http://codingbat.com/prob/p137918


i understood the chalenge now
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question