Suppose we have some lists, these are sorted. We have to merge these lists into one list. To solve this, we will use the heap data structure. So if the lists are [1, 4, 5], [1, 3, 4], [2, 6], then the final list will be [1, 1, 2, 3, 4, 4, 5, 6].To solve this, we will follow these steps −make one heapfor each linked list l in lists −if is in not 0, then insert I into a heapres := null and res_next := nullDo one infinite loop −temp := min of heapif heap has no element, then ... Read More
Suppose we have an input string s and another input string p. Here s is the main string and p is the pattern. We have to define one method, that can match patterns in the string. So we have to implement this for a regular expression, that supports ‘.’ And ‘*’.Dot ‘.’ Matches any single characterStar ‘*’ Matches zero or more of the preceding element.So for example, if the input is like s = “aa” and p = “a.”, then it will be true, for the same input string, if the patter is “.*”, then it will be true.To solve ... Read More
Suppose we have two arrays; these arrays are sorted. So we have to find the median of these two arrays. So if the arrays are like [1,5,8] and [2,3,6,9], then the answer will be 5.To solve this, we will follow these steps −Define a function findMedianSortedArrays, this will take nums1 and nums2 arraysif size of nums1 > size of nums2, then,Call the function return findMedianSortedArrays(nums2, nums1)x := size of nums1, y := size of nums2low := 0, high := xtotalLength := x + ywhile low
This example demonstrates how to Create Left to Right slide animation in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.transition.Slide import android.transition.TransitionManager import android.view.Gravity import android.view.View import android.widget.Button import android.widget.RelativeLayout import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { lateinit var btnSlideLeft: Button lateinit var btnSlideRight: Button lateinit var ... Read More
This example demonstrates how to Send an Intent to browser to open specific URL using KotlinStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.Example Step 3 − Add the following code to src/MainActivity.ktExampleimport android.content.Intent import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = "KotlinApp" } ... Read More
This example demonstrates how to validate an e-mail address in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml Step 3 − Add the following code to src/MainActivity.kt import android.import android.os.Bundle import android.view.View import android.widget.EditText import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { private lateinit var editText: EditText private lateinit var email: String private val emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\.+[a-z]+" override fun onCreate(savedInstanceState: ... Read More
This example demonstrates how to get Value of a Edit Text field in Android using Kotlin?Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.Button import android.widget.EditText import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { lateinit var button: Button lateinit var editText: EditText lateinit var string: String lateinit var textView: ... Read More
This example demonstrates how to find the latitude and longitude from address on Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.os.Handler import android.os.Message import android.widget.Button import android.widget.EditText import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { private lateinit var addressButton: Button private lateinit var textViewAddress: TextView lateinit var ... Read More
This example demonstrates how to add a footer in Android ListView using KotlinStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.view.ViewGroup import android.widget.ArrayAdapter import android.widget.ListView import androidx.appcompat.app.AppCompatActivity import java.util.* class MainActivity : AppCompatActivity() { private lateinit var listView: ListView var country = arrayOf( "India", "Australia", "South Africa", ... Read More
This example demonstrates how to Subscript and Superscript a String in Android using KotlinStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.text.SpannableStringBuilder import android.text.Spanned import android.text.style.RelativeSizeSpan import android.text.style.SubscriptSpan import android.text.style.SuperscriptSpan import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { lateinit var textView: TextView private lateinit var strText: String lateinit var spannableStringBuilder: SpannableStringBuilder override fun ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP