โœโœ Challenge โœโœ Find Out Given Array Is Trivalent Array Or Not... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

30th Oct 2017, 7:04 AM
Pranit Gandhi
Pranit Gandhi - avatar
33 Answers
+ 14
In simple terms, it means determine whether an array consist of 3 distinct elements. ๐Ÿ˜‰
31st Oct 2017, 5:04 AM
Zephyr Koo
Zephyr Koo - avatar
+ 13
Thanks for the challenge. Here's my try : https://code.sololearn.com/c3Wakn9R86Fq/?ref=app
30th Oct 2017, 1:52 PM
LukArToDo
LukArToDo - avatar
+ 12
@Pranit Gandhi Ofcourse. Here's inline in Java: https://code.sololearn.com/c5k81hDsgv8F/?ref=app
30th Oct 2017, 3:34 PM
LukArToDo
LukArToDo - avatar
+ 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
31st Oct 2017, 5:36 AM
Zephyr Koo
Zephyr Koo - avatar
+ 8
https://code.sololearn.com/cgAK05vex23Z/?ref=app
30th Oct 2017, 9:07 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 8
31st Oct 2017, 9:11 AM
Vahid Shirbisheh
Vahid Shirbisheh - avatar
+ 7
https://code.sololearn.com/ccDtjEX6PN0E/?ref=app
30th Oct 2017, 11:07 AM
Kรคzรฎ Mrรฎdรนl Hรธssรครฎn
Kรคzรฎ Mrรฎdรนl Hรธssรครฎn - avatar
+ 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
30th Oct 2017, 9:49 AM
visph
visph - avatar
+ 6
@Pranit..bro...check again.. I checked.. my code say.. trivalent
30th Oct 2017, 11:37 AM
Kรคzรฎ Mrรฎdรนl Hรธssรครฎn
Kรคzรฎ Mrรฎdรนl Hรธssรครฎn - avatar
+ 6
@sayan chandra: good complement to the minimalistic code of @VcC ;P
30th Oct 2017, 2:41 PM
visph
visph - avatar
+ 3
Example -4 Input-> {-1,0,1,-1,0,1,0,-1} Output-> Trivalent array(array contain 3 types of elements 1,0,-1)
30th Oct 2017, 7:05 AM
Pranit Gandhi
Pranit Gandhi - avatar
30th Oct 2017, 10:17 AM
Adib Attie
Adib Attie - avatar
+ 3
@zephyr yes it's 2,1 I missed semicolon
30th Oct 2017, 10:29 AM
Pranit Gandhi
Pranit Gandhi - avatar
+ 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
30th Oct 2017, 11:28 AM
Pranit Gandhi
Pranit Gandhi - avatar
30th Oct 2017, 11:38 AM
Rabee Abbas
Rabee Abbas - avatar
+ 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๐Ÿ’ช๐Ÿ‘
30th Oct 2017, 11:41 AM
Pranit Gandhi
Pranit Gandhi - avatar
+ 3
@Vcc@sayan python is best language most of the code are one line code
30th Oct 2017, 2:43 PM
Pranit Gandhi
Pranit Gandhi - avatar
+ 3
thanx @LukarTod
30th Oct 2017, 3:37 PM
Pranit Gandhi
Pranit Gandhi - avatar
30th Oct 2017, 9:16 AM
Rabee Abbas
Rabee Abbas - avatar
+ 2
@visph m sorry ๐Ÿค• it's my typo mistek that's y it happens I just updated it...
30th Oct 2017, 10:33 AM
Pranit Gandhi
Pranit Gandhi - avatar