Problem 50:(Round 2 Java Preparation)
Problem of the Day:
You want to sort words lexicographically without using inbuilt functions like Arrays.sort().
- Input:{"zebra", "apple", "mango", "ball", "cat",
"dog", "elephant", "fish", "ant", "bat"};
- Output:ant apple ball bat cat dog elephant fish mango zebra
1. Input: nums1 = [1, 3, 5, 7, 9]
nums2 = [2, 3, 5, 6, 8, 9]
Output: [1, 2, 3, 5, 6, 7, 8, 9]
2. Input: nums1 = [2, 4, 6, 8]
nums2 = [1, 3, 5, 7, 9]
Output: [1, 2, 3,4, 5, 6, 7, 8, 9]
.snippet-thumbnail img {
max-width: 50px;
height: auto;
object-fit: cover;
}
nums2 = [2, 3, 5, 6, 8, 9]
Output: [1, 2, 3, 5, 6, 7, 8, 9]
nums2 = [1, 3, 5, 7, 9]
Output: [1, 2, 3,4, 5, 6, 7, 8, 9]
class Q50 {
ReplyDeletepublic static void main(String[] args) {
String main = "Hel4oleglHell";
String sub = "ell";
System.out.println(isSubString(main, sub));
}
public static boolean isSubString(String main, String sub)
{
int count = 0;
int left = 0;
int right = 0;
while(left < main.length() && right < sub.length())
{
if(main.charAt(left) == sub.charAt(right))
{
count++;
right++;
left++;
if(count == sub.length())
{
return true;
}
}
else
{
count = 0;
right=0;
left++;
}
}
return false;
}
}