Funny Jav

💣 👉🏻👉🏻👉🏻 ALL INFORMATION CLICK HERE 👈🏻👈🏻👈🏻
Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Sign up or log in to customize your list.
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It only takes a minute to sign up.
The best answers are voted up and rise to the top
I'm a little rusty in Java, but I'm using it to get ready for interviews. Here's the problem description from HackerRank:
Suppose you have a string
S
which has length
N
and is indexed from
0
to
N−1
. String
R
is the reverse of the string
S
. The string
S
is funny if the condition
|Si−Si−1|=|Ri−Ri−1|
is true for every
i
from 1 to
N−1
.
(Note: Given a string str, stri denotes the ascii value of the ith character (0-indexed) of str. |x| denotes the absolute value of an integer x)
First line of the input will contain an integer T. T testcases follow. Each of the next T lines contains one string S.
For each string, print Funny or Not Funny in separate lines.
This passing solution took me about 20 minutes, so that might be a bit long given the difficulty of the problem. I'm open to critiques on my speed too.
19.9k22 gold badges6060 silver badges148148 bronze badges
Welcome to CodeReview, ironicaldiction. I hope you get some fine answers.
– Legato Sep 24 '15 at 3:14
Wouldn't it be easier to just keep two counters and not actually reverse the string? Seems a bit unnecessary to physically reverse when you can easily compute the math involved.
– corsiKa Sep 24 '15 at 7:01
Please do not edit your question to include changes you made due to answers. If you wish to indicate what changes you made, you should post a self-answer citing the answers you used to make your changes, or a new question if you still want improvements on your (new) code.
– Der Kommissar Sep 25 '15 at 18:16
The main loop starts at i = 2. That is, s.charAt(1) - s.charAt(0) is never attended to. Suspicious, isn't it?
A name comp (and comp2) presumes that it carries some information about comparison. It obviously doesn't. diff and rdiff sound better.
Reversal of the string just wastes time. You may work the same string from both directions simultaneously:
Returning the comparison result is an anti-pattern.
50.6k44 gold badges4545 silver badges127127 bronze badges
I would also suggest that you always use brackets for your if...else statements. It's generally accepted common practice and with good reason - the few lines that you save by not doing so lead to some very insidious bugs.
On an algorithmic note: why reverse the String at all? Use one loop and read the String both forwards and backwards simultaneously.
For further improvement, walk through a comparison manually:
What do you notice about the pairs 1. <-> 5. and 2. <-> 4.? There is a simpler solution to this problem than brute force...
1,1091010 silver badges1717 bronze badges
Your code is organized in a good way. Another thing I liked is that you have followed proper naming convention (i.e. Camel Case) while defining the function. However, there are few things that can be improved.
First of all, the code will give Compilation Error as the last } is missing in the code. Another thing is that, some imports like regex can be removed from the code as the functionality of those imports are never used in the code.
Another thing I have observed in your code that you are comparing both ascii values comp and comp2 and then returning the boolean after competing the for loop. Instead of that, you can return the false as soon as both ascii numbers are not same. This means we do not need to iterate through the whole string if a single difference doesn't match.
Apart from that, you have developed a function reverese to reverse the string and return the reversed string to the isFunny function. This thing (of passing a big string to the function, then doing some operation on each character and getting back into original one) can increase the time complexity as the maximum length of the string in this case can be 10000 (from description).
Actually, there is no need to reverse the String as the main goal is to compare ascii values of each character of two strings. We can directly get the ascii value of each character of reversed string without reversing the original String. So, my logic is as follows:
20.9k1212 gold badges3030 silver badges131131 bronze badges
20.3k22 gold badges3030 silver badges7676 bronze badges
Learning from the answers above can the code be optimized further as
// Complete the funnyString function below
You have presented an alternative solution, but haven't reviewed the code. Please edit to show what aspects of the question code prompted you to write this version, and in what ways it's an improvement over the original. It may be worth (re-)reading How to Answer.
– Toby Speight Aug 2 '19 at 14:37
Thanks for contributing an answer to Code Review Stack Exchange!
Use MathJax to format equations. MathJax reference.
By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy
Application support engineer (Moscow based)
JPMorgan Chase Bank, N.A.Moscow, Russia
Juni Technology ABNo office location
Machine Learning Lead| 100% Remote | (US Only)
The Remote CompanyNo office location
Cloud Infrastructure Engineer (f/m/d)
alfatraining Bildungszentrum GmbHNo office location
Product Manager - London Based - Remote
React.JS Software Developer - Remote
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.2.23.38634
Java Programmers Funny Jokes - HowToDoInJava
Funny String Java Solution - Code Review Stack Exchange
Java Tutorials | A Funny JAVA Discussion at TEA... - YouTube
JavFilm.tv sex jav Watch JAV HD Online, JAV Stream, JAV Streaming HD....
Легендарные Java-игры. Часть 1 | Для Олдов | Яндекс Дзен
Hookers In Ireland
Black Girl Escorts
Accidental Flashing
Funny Jav














































