?
Solved

parentbit challenge

Posted on 2016-09-21
3
Medium Priority
?
156 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

719 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