Form a Triangle Problem Statement
You are given an array of integers ARR
with a length of N
. Your task is to determine whether it's possible to construct at least one non-degenerate triangle using the values from the array as the sides of the triangle. If possible, return true
; otherwise, return false
.
Input:
The first line contains a single integer 'T' denoting the number of test cases.
For each test case:
The first line contains a single integer 'N' denoting the number of elements in the array.
The second line contains 'N' space-separated integers denoting the elements of the array.
Output:
For each test case, return "YES" if it is possible to form a non-degenerate triangle, otherwise return "NO". Each test case output should be printed on a separate line.
Example:
Input:
2
3
3 4 5
4
1 10 12 30
Output:
YES
NO
Constraints:
1 ≤ T ≤ 100
3 ≤ N ≤ 10^3
0 ≤ ARR[i] ≤ 10^9
Note:
You are not required to print anything since this is already managed by the system. Your goal is to implement the functionality that returns the correct result.
AnswerBot
2mo
Determine if it's possible to form a non-degenerate triangle using array elements as sides.
Check if the sum of any two sides is greater than the third side to form a triangle.
If any such combination e...read more
Anonymous
1y
#include <bits/stdc++.h> bool possibleToMakeTriangle(vector<int> &arr) { // Write your code here. int n=arr.size(); if (n<3) return false; sort(arr.begin(),arr.end()); for(int i=0;i<n-2;i++){ if(arr[i...read more
Help your peers!
Add answer anonymously...
PhonePe Software Developer interview questions & answers
A Software Developer was asked 01 Jun 2022Q. Insertion in AVL Tree Problem Statement You are required to implement an AVL Tre...read more
A Software Developer was asked 01 Jun 2022Q. Unlock the Briefcase Problem Statement You have a briefcase secured by a lock wi...read more
A Software Developer was asked 01 Jun 2022Q. Minimum Moves to Collect All Keys Given an 'N' x 'M' grid, find the minimum numb...read more
Popular interview questions of Software Developer
A Software Developer was asked Q1. Insertion in AVL Tree Problem Statement You are required to implement an AVL Tre...read more
A Software Developer was asked Q2. Unlock the Briefcase Problem Statement You have a briefcase secured by a lock wi...read more
A Software Developer was asked Q3. Minimum Moves to Collect All Keys Given an 'N' x 'M' grid, find the minimum numb...read more
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app