You are given an array of words (strings) and an integer k k k. Your task is to write a function that returns the k k k longest words from the array. If there are fewer than k k k words in the array, return all the words sorted by length in descending order. If there are ties in length, return the words in alphabetical order. Input: An array of strings words[] where each string consists of lowercase and uppercase letters only. An integer k k k (1 ≤ k k k ≤ 100). Output: An array of the k k k longest words, sorted by length (and alphabetically if lengths are equal). Example: plaintextInput: words = ["apple", "banana", "kiwi", "grape", "watermelon"], k = 3 Output: ["watermelon", "banana", "apple"] Input: words = ["cat", "bat", "rat"], k = 5 Output: ["bat", "cat", "rat"] Constraints: The output array should not exceed k k k elements. You may assume that the input will always have at least one word.
Senior Java Developer Interview Questions
5,573 senior java developer interview questions shared by candidates
Prepare for every topics that are needed.
How to deploy the app to multiple environment ?
Java coding snippet Java stream API Spring boot framework
Questions were general like on Spring, Core Java, microservices.
About Current Company? Why Job change? Java related Question?
Bubbled sort, palindrome, java8 Stream program, create own Linked list and some java core concepts and spring boot concepts
Find max value of a couple of streams only using stream API without collecting the data to any structure.
Are you ready for assessment?
in Interview They ask from core java, spring, hibernate, JMS, basics of linux, design pattern
Viewing 371 - 380 interview questions
See Interview Questions for Similar Jobs
Senior Java EngineerJava Applications DeveloperSenior DeveloperJava Web DeveloperJava DeveloperSenior Software EngineerJava ConsultantJ2ee DeveloperJava ProgrammerSenior Software DeveloperSenior Web DeveloperJava Software DeveloperHybris DeveloperJava Software EngineerJava ArchitectTechnical Team Lead