+ 9
✍✍ Challenge ✍✍ Find Out Given Array Is Trivalent Array Or Not...
Define an array to be Trivalent Array if all of its elements are one of "three value." Example -1 Input-> {10,99,24,10,99,24} Output-> Trivalent array(array contain only 3 types of elements 10,24,99) Example -2 Input-> {1,2,2,1,2,1} Output-> it is not a Trivalent array(array contain only 2 types of elements 1,2) Example -3 Input-> {10,20,20,30,40} Output-> it is not a Trivalent array(array contain 4 types of elements 10,20,30,40) (More Example in cmnts) https://code.sololearn.com/c89SIHppyT5L/?ref=app
34 Answers
+ 14
In simple terms, it means determine whether an array consist of 3 distinct elements. 😉
+ 13
Thanks for the challenge.
Here's my try :
https://code.sololearn.com/c3Wakn9R86Fq/?ref=app
+ 12
@Pranit Gandhi
Ofcourse. Here's inline in Java:
https://code.sololearn.com/c5k81hDsgv8F/?ref=app
+ 12
Here's my Java implementation! ✌
Stream API One-Liner〰
Arrays.stream(arr).distinct().count() == 3
To be honest I'm used to submit LINQ solution in C# but since you asked in Java, here's how it's done with Java Stream API. Enjoy~ ❤
https://code.sololearn.com/cCWP8gHPZX2s/?ref=app
+ 8
https://code.sololearn.com/cgAK05vex23Z/?ref=app
+ 8
Here is my try in Java:
https://code.sololearn.com/clHgzh28Yd9X
+ 7
https://code.sololearn.com/ccDtjEX6PN0E/?ref=app
+ 6
This is confusing: you (and other followed you) wrote "travelent"/"travelant" many times (including the question title) until we get access to the code title (on web site you doesn't see the code name, just the url showing only its ID) at end of the post, where you correctly spell it as "trivalent" wich make more sense ^^
Reading "travele/ant" that sound to me about "travel", so I didn't understand the logic behind, until I finally read "TRIVALENT" :P
+ 6
@Pranit..bro...check again..
I checked..
my code say.. trivalent
+ 6
@sayan chandra: good complement to the minimalistic code of @VcC ;P
+ 3
Example -4
Input-> {-1,0,1,-1,0,1,0,-1}
Output-> Trivalent array(array contain 3 types of elements 1,0,-1)
+ 3
@zephyr
yes it's 2,1
I missed semicolon
+ 3
@rabee
in that way your program is right
but in this challenge you have to take array from user and just show that it is Trivalent or not do some modifications you will get answers
+ 3
@kazi Mridul hossain
I forgot to put comma.
I just kept elements seperated by space
that's y it gives different output
it's working best one💪👍
+ 3
@Vcc@sayan
python is best language
most of the code are one line code
+ 3
thanx @LukarTod
+ 2
@visph
m sorry 🤕
it's my typo mistek that's y it happens
I just updated it...