Problems - Set 1
Easy
FizzBuzz
Given a positive integer A, return an array of strings with all the integers from 1 to N. But for multiples of 3 the array should have “Fizz” instead of the number. For the multiples of 5, the array should have “Buzz” instead of the number. For numbers which are multiple of 3 and 5 both, the array should have “FizzBuzz” instead of the number.
Example:
Method 1 - Using loop and if else
Method 2 - Using StringBuilder for String Concatenation
Instead of performing multiple concatenations using +
inside the if
conditions, use a StringBuilder
to construct the strings. This can improve performance when dealing with large datasets.
Method 3 - Using Streams (Java 8+)
If we want to use a more functional programming style, we can leverage Java Streams.
Store and calculate mathematical expression
Write a function to add one simple mathematical expressions which are of the form Ax^a + Bx^b + . . . (where the coefficients and exponents can be any positive or negative real number). Store the input values into a proper data structure.
Method 1: Bad Implementation
Method 2: Better Implementation
Last updated
Was this helpful?