Suppose there is a new alien language and that uses the latin alphabet. However, the order among letters are not known. We have a list of non-empty words from the dictionary, these words are sorted lexicographically by the rules of this new language. we have to find the order of letters in this language.So, if the input is like ["wrt", "wrf", "er", "ett", "rftt" ], then the output will be "wertf"To solve this, we will follow these steps −Define one map called degreeDefine one map called graphn := size of wordsfor initialize i := 0, when i < size of ... Read More
Suppose we have n houses in a row, now each house can be painted with one of the k colors. The painting cost of each house with a certain color is different. Now we have to keep in mind that we have to paint all the houses such that no two adjacent houses have the same color.The cost of painting each house with a certain color is represented by a matrix of order n x k. And we have to find the minimum cost to paint all houses.So, if the input is like153294then the output will be 5, as paint ... Read More
Suppose we want to define a function to count the total strobogrammatic numbers that exist in the range of (low and high). As we know that a strobogrammatic number is a number that looks the same when rotated 180 degrees.So, if the input is like low = "50", high = "100", then the output will be 3 as there are three results, 69, 88, and 96.To solve this, we will follow these steps −Define a function findStrobogrammatic(), this will take n, Define an array retif n & 1 is non-zero, then −insert "0" at the end of retinsert "1" at ... Read More
This example demonstrates how to change the language of an app when the user selects language 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.Example Step 3 − Add the following code to src/MainActivity.ktimport android.content.Intent import android.os.Bundle import android.view.View import android.widget.AdapterView import android.widget.AdapterView.OnItemSelectedListener import android.widget.ArrayAdapter import android.widget.Spinner import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import java.util.* import kotlin.system.exitProcess @Suppress("DEPRECATION") class MainActivity : AppCompatActivity() { lateinit var spinner: Spinner lateinit var locale: ... Read More
The call(), apply() and bind() are used to borrow methods in JavaScript.Following is the code for borrowing methods in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: 500; color: rebeccapurple; } .result { color: red; } Borrowing a method in JavaScript CLICK HERE Click on the above button to borrow the welcome method of object obj ... Read More
Following is the code to transform JavaScript arrays using maps.Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result,.sample { font-size: 18px; font-weight: 500; color: rebeccapurple; } .result { color: red; } Transform JavaScript arrays using maps [22,33,44,55] CLICK HERE Click on the above button to square each element of the above array let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); let arr = [22, 33, 44, 55]; BtnEle.addEventListener("click", () => { resEle.innerHTML = arr.map((a) => a * a); }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −
Following is the code to de-structure already declared variables in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: rebeccapurple; } De-structure to already-declared variables CLICK HERE Click on the above button to destructure the personObj object let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); let name, age, personObj; personObj = { name: "Rohan", age: 19, }; BtnEle.addEventListener("click", () => { ({ name, age } = personObj); resEle.innerHTML = " name = " + name + "age = " + age; }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −
Following is the code to pass an object of parameters to a function −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: 500; color: rebeccapurple; } .sample { color: red; } Passing an object of parameters into a function CLICK HERE Click on the above button to add 4 object values by passing them to a function let ... Read More
Following is the code to merge objects into a single object array −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: 500; color: rebeccapurple; } .sample { color: red; } Merge objects into a single object array [{id:22, class:7}, {name:'Rohan', age:12}, {state:'Delhi', country:'India'}] CLICK HERE Click on the above button to merge the above objects inside array into ... Read More
This example demonstrates how to put a ListView into a ScrollView without it collapsing on Android in 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.Example Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.ArrayAdapter import android.widget.ListView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { private val listViewArray = arrayOf( "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "Eleven", "Twelve", ... Read More