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

Largest Odd number in a string #216

Closed
ultimatecoder2 opened this issue Oct 7, 2021 · 5 comments · Fixed by #225
Closed

Largest Odd number in a string #216

ultimatecoder2 opened this issue Oct 7, 2021 · 5 comments · Fixed by #225
Assignees
Labels
Easy good first issue Good for newcomers hacktoberfest-accepted Hacktoberfest 2022 accepted issues Strings

Comments

@ultimatecoder2
Copy link
Collaborator

You are given a string num, representing a large integer. Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or an empty string "" if no odd integer exists.

A substring is a contiguous sequence of characters within a string.

Sample Test Case 1:

Input: num = "52"
Output: "5"
Explanation: The only non-empty substrings are "5", "2", and "52". "5" is the only odd number.

Sample Test Case 2:

Input: num = "4206"
Output: ""
Explanation: There are no odd numbers in "4206".

@ultimatecoder2 ultimatecoder2 added Easy good first issue Good for newcomers hacktoberfest-accepted Hacktoberfest 2022 accepted issues Strings labels Oct 7, 2021
@nishantkantojha
Copy link

Hi @ultimatecoder2,
Please have a look on the below solution 😄

#include <iostream>
#include <string>
using namespace std;

string largestOddNumber(string num){
    for(int i = num.size()-1;i>=0; i--){
                    if((num[i] - '0')%2 == 0)
                num.erase(num.begin() + i);
            
            else break;
    }
            return num;
} 

int main()
{
string number="";
cin >> number;
cout << largestOddNumber(number)<<endl;
return 0;
}

@nishantkantojha
Copy link

I don't know how to reply to a PR.

Waiting for some positive reply ☺️

@nishantkantojha
Copy link

I just saw few comments on other issues and seems like this is not the proper way to contribute. I mean not to directly giving the possible solution.

I apologize for the above inconvenience if it happens.

@ultimatecoder2
Copy link
Collaborator Author

Good @nishantkantojha . Your solution seems to be fine. I am assigning this issue to you, so that you can take your time to initiate a pull request.

To contribute to this repository, you can try following this video:
https://drive.google.com/file/d/1QoXaWDvIwgksPrwogE2JHzcoZqa7MQib/view

For any queries, feel free to ask. We would love to see your first pull request. It will also help you to learn more about Git and Github.

dhananjay8968 pushed a commit to dhananjay8968/Open-Source that referenced this issue Oct 8, 2021
Auleen added a commit to Auleen/Open-Source that referenced this issue Oct 8, 2021
@Ruchika-20
Copy link
Contributor

Ruchika-20 commented Oct 8, 2021

hey...can i work on this issue?
I would like to provide C++ implementation of above problem

@Gauravsharma-20 Gauravsharma-20 linked a pull request Oct 8, 2021 that will close this issue
Gauravsharma-20 added a commit that referenced this issue Oct 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Easy good first issue Good for newcomers hacktoberfest-accepted Hacktoberfest 2022 accepted issues Strings
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants