instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a JavaScript code that implements a binary search algorithm.
arr = [1, 3, 5, 7, 9, 11]
target = 11
The code should be able to handle large arrays of up to 10^6 elements efficiently. | codefeedback |
Write a Java program to create a class for a circle, with parameters for the radius and center coordinates, and methods for calculating the area and circumference of a circle, as well as checking if a given point is inside the circle. | codefeedback |
Use LINQ syntax to create a query that returns all items from an array of strings, where the length of the string is greater than 5, and the string contains both uppercase and lowercase letters. | codefeedback |
Write a Python program that finds the longest common subsequence of two strings, while also considering the case sensitivity and whitespace.
str1 = "The quick brown fox jumps over the lazy dog"
str2 = "The Quick Brown Fox Jumps Over The Lazy Dog"
In this case, the program should consider "The quick brown fox jumps ov... | codefeedback |
Write a C++ code that implements the selection sort algorithm to sort an array of integers in descending order. The array must have at least 5 elements. | codefeedback |
Generate a SQL query to select all the columns from a table named 'department' where the department name is 'Marketing' and the department has at least 10 employees. | codefeedback |
Create a function `calculate_discount` to calculate 20% discount for a given price. The function should only accept prices that are greater than or equal to 10. If the price is less than 10, the function should raise a `ValueError` with the message "Invalid price: price must be greater than or equal to 10". Additionall... | codefeedback |
Explain how to traverse a binary tree using breadth-first search (BFS) and provide the implementation in Python. Additionally, explain the time and space complexity of your implementation. | codefeedback |
Write a regular expression that captures all the words starting with "A" and ending with a digit. | codefeedback |
Create a function that detects whether a given string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward.
The function should take in a string as an input and return True if the string is a palindrome, and False otherwise. The function shou... | codefeedback |
Assign 1 to all the elements of a 2D array that are divisible by 3. Then, return the sum of all the assigned elements.
arr = [[1,2,3,4,5,6],
[10,15,20,25,30,35],
[3,8,6,12,9,18],
[7,14,21,28,35,42],
[16,32,48,64,80,96],
[27,54,81,108,135,162]]
#Difficulty Increase:
- The size of the... | codefeedback |
Create an array of the squared values of all elements of the given array. The squared values should be in descending order. The input array must contain at least 5 elements. The squared values should be stored in a separate array. arr = [2, 3, 6, 8, 4, 9, 7] | codefeedback |
Create a function called `convert_csv_to_json` to convert the following csv to the corresponding JSON format. The csv contains information about cities and their geographical coordinates.
The csv file is structured as follows:
- The first line contains the headers: "city", "country", "latitude", and "longitude".
- The... | codefeedback |
Select all the records in the given table where the ID is a prime number greater than 5.
Table
ID | Name | Address
1 | John | UK
2 | Jack | US
5 | Mary | UK
11 | Chris | Canada
17 | Tom | Australia | codefeedback |
Write a function that takes an integer as an argument and prints its least significant digit. Additionally, the function should calculate and print the sum of the least significant digit and the second least significant digit. | codefeedback |
Differentiate the methods of machine learning and explain the differences in terms of their time complexity and space complexity. | codefeedback |
Create a function called `replace_words` which replaces all the words specified in the given list of words with their corresponding synonyms. The function should handle multiple synonyms for each word. The input string may contain punctuation and uppercase letters. The function should preserve the original capitalizati... | codefeedback |
Explain how a support vector machine works, and provide a step-by-step explanation of how it finds the optimal hyperplane for classification. | codefeedback |
Transform the given list of integers by squaring each number and then printing the transformed list in descending order.
nums = [-5, -2, 3, 7, 1]
#Expected Output:
[49, 25, 9, 4, 1] | codefeedback |
Convert the following snippet from ES6 to ES5, but also refactor it to use a closure for encapsulation:
const multiply = (x, y) => { return x * y }; | codefeedback |
Writing a regex pattern to match words starting with "Py" and ending with "thon" and containing at least one uppercase letter. | codefeedback |
Filter out the integers from the list that are divisible by 6 and are also prime numbers.
nums = [1, 2, 4, 6, 7, 8, 10, 12, 14, 18]
#Explanation#
In the given test, we need to filter out the integers from the list that are divisible by 6. However, to increase the difficulty, we will also consider only those numbers th... | codefeedback |
Generate a random string with the following conditions:
1. The string must start with a capital letter.
2. The string must contain at least one special character (!, @, #, $, %, ^, &, *) and at least one digit (0-9).
3. The string must have a length of at least 8 characters.
4. The string must not contain any repeating... | codefeedback |
Find the area of a triangle using the Heron's formula
lengths = [7, 9, 13] | codefeedback |
Using python, implement a method to find the longest common subsequence in two strings while considering that the subsequence should contain only alphabetical characters. The two strings should have a minimum length of 5 characters each.
str1 = "AGGTAB"
str2 = "GXTXAYB" | codefeedback |
Generate an 8 character random string that does not contain any vowels. | codefeedback |
Write a function to remove all occurrences of a specified element from a given list and return the modified list.
Example:
Input: [2, 4, 8, 9, 4], element = 4
Output: [2, 8, 9]
Additional Requirements:
1. The function should handle both empty lists and lists with no occurrences of the specified element.
2. The functio... | codefeedback |
Develop an algorithm to print all the possible n-ary trees with a given number of nodes, where each node can have at most k children. n=4, k=3 | codefeedback |
Please implement a function `validate_IPv4` that takes a string `IP` as input and returns a boolean value indicating whether the given string is a valid IPv4 address.
A valid IPv4 address consists of four decimal numbers separated by periods. Each decimal number must be between 0 and 255, inclusive. Leading zeros are ... | codefeedback |
Write a function to find all elements that appear more than once in a given array. The function should return the elements in ascending order and should also remove any duplicate elements from the result. Additionally, you should not use any built-in functions or libraries to solve this problem. The input array will ha... | codefeedback |
Suppose a web page contains an unknown number of parameters. Write a function to count the number of parameters present in a given URL. The function should have a time complexity of O(n) and a space complexity of O(1), where n is the length of the URL. Additionally, the function should handle URLs with nested parameter... | codefeedback |
Write a JavaScript function that takes an array of integers as an argument and returns the sum of all prime numbers in the array. | codefeedback |
You need to write an algorithm to find the third largest value in a Binary Search Tree, but you are not allowed to use any built-in data structures or methods to traverse or manipulate the tree. You must implement your own tree data structure and the necessary algorithms to perform the required operations. | codefeedback |
Create a Python program to convert a given temperature in Celsius to Kelvin. Additionally, provide a piece of erroneous code as a reference to increase misdirection. | codefeedback |
Create a script to delete all system logs that are older than 30 days, excluding logs in the "important" folder. Additionally, the script should create a backup of all deleted logs in a separate directory with the current date and time appended to the file name. | codefeedback |
Write a Java program to find all pairs of integers from an array whose sum equals a given number, but with the additional constraint that each integer can only be used once in a pair. | codefeedback |
Modify a given shell script to generate a text-based report of the commands run in the bash shell, excluding any commands that contain a specific keyword specified by the user. Additionally, the report should include the execution time of each command in milliseconds. | codefeedback |
Train a Random Forest classifier in Python on the Iris dataset with a minimum of 100 trees and a maximum depth of 10. | codefeedback |
Determine the function of the Bluetooth signal in the given program.
void setup() {
Serial.begin(9600);
Bluetooth.begin(9600);
}
void loop() {
BluetoothSignal();
}
void BluetoothSignal() {
// Code to send a signal to the Bluetooth module.
// Your task is to modify the BluetoothSignal function to handle mu... | codefeedback |
Write a function in Python to normalize a given string by removing white spaces, changing to lower case, replacing special characters with underscores, and removing duplicate words. The function should also return the normalized string in reverse order.
"Hello World! How are you? Are you ready for this test?" | codefeedback |
Implement a depth-first search (DFS) algorithm for a tree data structure with the following additional constraints:
- The tree is not guaranteed to be binary, it can have any number of child nodes for each parent node.
- The tree can be arbitrarily large, with up to 1 million nodes.
- Each node in the tree has a uniqu... | codefeedback |
Construct a program in Java to sort an array of String objects in descending order. The program should have a time complexity of O(n log n) and should not use any built-in sorting functions or libraries. | codefeedback |
Construct a data mining program to mine public internet data from Twitter datasets. The program should include the following steps:
1. Authenticate with the Twitter API using OAuth 2.0 for secure access to the datasets.
2. Use the Twitter API to search for relevant tweets based on specific criteria, such as keywords, ... | codefeedback |
Write the Big O time complexity of the given algorithm.
Algorithm: Finding the value at a given index of a multidimensional unordered array. | codefeedback |
You need to develop a code that takes two strings and returns a boolean if the substrings are anagrams. However, you must now handle cases where the input strings contain spaces and punctuation marks.
Strings: "Hello, World!" and "world hello!" | codefeedback |
Given two strings, develop a function to calculate the Levenshtein distance between them.
References:
Levenshtein distance is a string metric for measuring the difference between two strings. In simple terms, it calculates the minimum number of single-character edits (insertions, deletions, or substitutions) required ... | codefeedback |
Develop a function to encode a text string using the Caesar cipher with a variable shift. The shift value should be provided as an argument to the function.
For example, given the string "Hello World" and a shift value of 3, the encoded string would be "Khoor Zruog".
The Caesar cipher works by shifting each letter i... | codefeedback |
Create an algorithm that sorts a given list of numbers in descending order and has a time complexity of O(nlogn). | codefeedback |
Create a JavaScript program to make a TCP connection to the server and retrieve the current date and time. | codefeedback |
Create an algorithm to implement a stack using a single queue, while also ensuring that the time complexity for both push and pop operations is O(1). | codefeedback |
Create an HTML form that takes three inputs: a name, an email address, and a password. When the submit button is clicked, validate the inputs using JavaScript and display appropriate error messages if any of the inputs are empty or if the email address is not in a valid format (e.g. missing "@" symbol). Additionally, h... | codefeedback |
Create a React app that loads data from a given REST API endpoint and displays it in a custom-designed grid component. The grid component should have pagination, sorting, and filtering functionality. Additionally, implement a feature that allows the user to update the data on the server-side through the API. | codefeedback |
Given the following nested loop structure, write code to print all elements in the array. The code must be implemented using recursion and must not use any loops or iteration constructs. arr = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]. | codefeedback |
List the types of inheritance supported in Java and provide an example of each type. Also, include a piece of erroneous code that demonstrates a common mistake when using one of these types of inheritance. | codefeedback |
Create a Java program for finding the largest number among an array of n integers. The program should have a time complexity of O(n) and should not use any built-in functions or libraries. | codefeedback |
Write a PHP script to connect to a MySQL database and insert a row in the table with values in given fields. Additionally, implement a check to ensure that the inserted email address is unique and does not already exist in the database before inserting the row. | codefeedback |
Suppose you have a list of numbers and you want to add all the numbers together. Write a loop to do so.
Requirements:
- The time complexity of the solution should be O(n), where n is the number of elements in the list.
- The space complexity of the solution should be O(1), i.e. it should use constant extra space regar... | codefeedback |
Physicists often use the constant, Planck's constant, to measure the frequency of light waves. What is the value of Planck's constant in electron volts (eV)? | codefeedback |
Convert a string of characters to uppercase in JavaScript, without using any built-in string manipulation functions or methods. String: hello | codefeedback |
Given two lists, write a Python program to print all common elements in them. The program should also remove duplicates from the final list and sort it in ascending order. Additionally, the program should have a time complexity of O(n) and should not use any built-in functions or libraries.
list1 = [10, 20, 30, 40, 4... | codefeedback |
Gather data from the web page and write a C# program to extract the page title. The program should also remove any HTML tags and extract the main content of the page. | codefeedback |
Modify the following given program to print all prime numbers between 1 and n, where n is a positive integer greater than 1 and less than or equal to 10^9. Additionally, the program should utilize a multi-threaded approach to improve the efficiency of the prime number generation. | codefeedback |
Modify the given code to generate the Fibonacci sequence up to the nth term, without using recursion and without using any additional data structures. | codefeedback |
Write a code to establish a connection between your server and a remote database. The remote database is hosted on a server with a dynamic IP address and the server is behind a firewall. You need to retrieve the database IP address and the firewall rules dynamically before establishing the connection.
Server host: dyn... | codefeedback |
Create a code that removes all duplicate elements in a given array, while also keeping track of the count of each unique element. Additionally, the code should return the unique elements in descending order based on their count. Array: [5, 10, 5, 7, 10] | codefeedback |
Write a code to implement insertion sort on a given list. The list contains unique positive integers only. The maximum length of the list is 100. | codefeedback |
Write a code to create a 3x3 matrix with all elements 1, but each row and column must have unique values. | codefeedback |
Create a script to remove specific HTML tags from a web page. The script should remove all instances of the <p> and <title> tags from the following web page:
<html>
<head>
<title>Example</title>
</head>
<body>
<p>Welcome to example.com</p>
</body>
</html> | codefeedback |
Write a code to fetch the last 4 commits of a git repository, but only include the commits made by a specific user. The user's username is 'rnyagah' and the repository name is 'GPT-Evaluation'. | codefeedback |
Create a FOR loop to print out the odd numbers between a given range. However, before printing each odd number, check if it is divisible by 3. If it is divisible by 3, skip it and move on to the next number. Additionally, after printing each odd number, check if it is a prime number. If it is a prime number, print "Pri... | codefeedback |
Create a text classifier using a Random Forest algorithm to classify a dataset of movie titles and their corresponding genres. The input dataset is provided as a list of lists, where each inner list contains a movie title as the first element and the genre as the second element. The goal is to train the classifier to a... | codefeedback |
Create a subclass 'Manager' of Employee and add the following fields: 'experience', 'teamSize', and 'performanceRatings'. Additionally, implement the following methods:
1. A method to calculate the average performance rating for the manager's team.
2. A method to find the manager with the highest team performance rati... | codefeedback |
Code a while loop statement to print a string with the value of the variable num, but only if the value of num is between 1 and 100 (inclusive). If the value of num is not within this range, print an error message instead. Additionally, after printing each value of num, add 1 to the value of num until it reaches 100. | codefeedback |
Design a linked list data structure with the following operations:
1. `void insert(int val)` - Inserts the element `val` at the beginning of the linked list.
2. `void delete(int val)` - Deletes the first occurrence of `val` in the linked list, if it exists.
3. `int search(int val)` - Returns the index of the first occ... | codefeedback |
Below is the code of a shopping list application. Modify it to add a function to calculate the total cost of all items in the list. Additionally, the function should exclude any items that have a price greater than $10 and should round the total cost to the nearest cent. Return the total cost as a string with the dolla... | codefeedback |
Create a list of 5 positive prime numbers and print out their product. | codefeedback |
Write a code to input an array and find the maximum and minimum element in it. The array can contain both positive and negative integers. Additionally, you need to find the second minimum and second maximum elements in the array. The size of the array will not exceed 1000 elements.
arr = [1, -2, 3, 4, -5, 6, -7, 8] | codefeedback |
Write a code to find the maximum of 5 arguments.
#Additional Instructions#
1. The code should not use any built-in functions or libraries to find the maximum value.
2. The code should handle both positive and negative integers as arguments.
3. The code should handle decimal numbers as arguments.
4. The code should... | codefeedback |
Print the duplicated items in an array of integers in ascending order, where the array size is limited to 1000 and the elements are in the range of -1000 to 1000. If there are no duplicates, output "No duplicates found." array: [1, 2, 3, 2, 5, 1] | codefeedback |
Create a function that takes a string, a keyword, and a replacement word, then delete all the occurrences of the keyword in the given string and replace them with the replacement word. The function should be case-sensitive and should also count and return the total number of occurrences of the keyword in the string. Ad... | codefeedback |
Write a code in Java to print out the power of two of the given number, while ensuring the output is in ascending order and each power is separated by a comma.
Number: 4 | codefeedback |
Evaluate the expression (2^3 - 5) * (4 + 6/2) + 9%4. | codefeedback |
Implement a search algorithm to search for a node in a binary search tree with a time complexity of O(log n). The algorithm should also keep track of the number of comparisons made during the search process. | codefeedback |
What is the Big O notation of the algorithm you wrote in Task 8? Provide a detailed analysis of the time and space complexity of the algorithm, explaining any assumptions or optimizations made. | codefeedback |
Write a code to traverse a matrix in spiral form while keeping track of the sum of all the elements. | codefeedback |
Given a string and two words, write a program to find the shortest subsequence containing both words. A subsequence is defined as a sequence of characters that appears in the same order as they do in the original string, but not necessarily consecutively. The program should return the subsequence with the minimum numbe... | codefeedback |
Write an SQL query that returns the total number of items per category, but exclude any categories that have less than 5 items. | codefeedback |
Construct a loop that prints the Fibonacci numbers up to the 10th term, one number per line. | codefeedback |
Suggest an efficient algorithm to filter out comments containing profane language in a large text corpus, while also considering context and variations of profanity. Additionally, the solution should be able to handle multilingual comments and provide an accurate profanity detection rate, minimizing false positives and... | codefeedback |
Generate a unique 9-digit hexadecimal code that is a prime number. | codefeedback |
Create a switch statement to convert an RGB value to HEX. The RGB value should be limited to values between 0 and 255, and an error message should be displayed if any of the values are outside this range. The HEX value should be formatted as a 6-digit string preceded by a '#' symbol. Additionally, the program should ha... | codefeedback |
Explain the process of k-fold cross-validation in machine learning and discuss its advantages and disadvantages compared to other validation techniques. | codefeedback |
Count the number of occurrences of the letter "a" followed by the letter "b" in a given string. The letter "a" and "b" must be in the same order and adjacent to each other. The input string may contain uppercase and lowercase letters, spaces, and punctuation marks.
string = "My favorite animal is a dabbing dog" | codefeedback |
Suggest a way to generate random passwords using Python with the following requirements:
1. The password must be at least 12 characters long.
2. The password must contain a combination of uppercase and lowercase letters, numbers, and special characters.
3. The password must not contain any repeating characters.
4. The ... | codefeedback |
Write a script in Python to make an http request and extract the title of the web page. However, you are not allowed to use any third-party libraries or modules for making the http request or parsing the HTML. You must implement the entire functionality from scratch using only built-in Python modules. | codefeedback |
Perform a bubble sort on the following array of numbers. The array may contain duplicates and the length of the array can be up to 100,000 elements. The input array can be modified in place. | codefeedback |
Find the longest word in a piece of text. Make sure to handle cases where there are multiple words with the same length and return the first occurrence of the longest word.
Example:
Input: "The quick brown fox jumps over the lazy dog"
Output: "jump"
Note: The input text will only contain alphabetical characters and s... | codefeedback |
What is the factorial of a positive integer n, where 1 ≤ n ≤ 10? | codefeedback |
Write a JavaScript function that takes in a number as input and checks if it is a whole number or has decimals. If the number is a whole number, return true. If the number has decimals, return false.
In your solution, you should not use any built-in JavaScript functions that directly check for whole numbers. Instead, ... | codefeedback |
Find the longest substring of three characters that is a palindrome.
string = "banana" | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.