instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Perform a linear search on an array of 1,000,000 numbers and return the index for the target number. The array should be randomly generated with numbers ranging from -1,000,000 to 1,000,000.
target_num = 500,000
#Sample Solution#
def linear_search(nums, target_num):
for i in range(len(nums)):
if nums[i] ==... | codefeedback |
Parse a string containing HTML markups and extract the text content. The HTML string may contain nested elements and multiple occurrences of the same tag. Return the extracted text content as a list of strings, where each element represents the text content of a separate HTML element.
Example:
html_string = '<html><bo... | codefeedback |
Using the input, create a new list of strings where all strings in the new list have an uppercase first letter and do not contain any vowels.
my_list = ["hello", "world", "how", "are", "you?"] | codefeedback |
Create a SQL query to find the top 3 employees who are earning the highest salary, ordered by their salary in descending order. | codefeedback |
Suggest a technique to detect plagiarism in programming assignments that specifically focuses on detecting code similarity using natural language processing techniques. | codefeedback |
Create an object-oriented JavaScript class to represent a point in two-dimensional space. The class should have methods to calculate the distance between two points, find the closest point to a given point from a list of points, and determine if a point lies on a given line segment. The point coordinates should be rest... | codefeedback |
Explain the step-by-step process of setting up a local development environment for a Node.js application on a Linux machine, including the installation and configuration of necessary tools and dependencies. Additionally, provide instructions on how to deploy the application on a local server and test its functionality. | codefeedback |
Generate a correct SQL statement to select the employees with their name, gender, age, salary and department. Additionally, include a condition to filter the results for employees whose salary is above the average salary of their respective department. | codefeedback |
Create a function in C++ that will sort a given array of integers in ascending order of their values. However, you are not allowed to use any built-in sorting functions or algorithms. You must implement your own sorting algorithm.
unsorted_arr = {45, 21, 12, 56, 7, 47, 34}
Time Complexity: Your sorting algorithm shou... | codefeedback |
Create a python program that takes a string as input and prints the length of the longest substring without repeating characters. The program should also print the actual longest substring.
For example, if the input string is "abcabcbb", the program should output:
Longest substring without repeating characters: "abc"
... | codefeedback |
Write a SQL query to retrieve all rows from the table 'movies' whose genre is 'comedy' and whose rating is greater than or equal to 7. | codefeedback |
Given two strings, find the longest common substring between them and print it. The longest common substring should consist of at least three characters and be case-sensitive. The input strings should be alphanumeric and have a length of at least five characters each.
string1 = "HelloWorld"
string2 = "HelloWorld!" | codefeedback |
Create a JavaScript function that takes an array of numbers and returns true if every element is an even number and false otherwise. In addition, the function should throw an error if any element in the array is not a number. | codefeedback |
Implement a class hierarchy for a zoo simulation. The hierarchy should include a base class called "Animal" with subclasses such as "Mammal," "Reptile," and "Bird." Each subclass should have at least two unique properties and one unique method. Additionally, the "Animal" class should have a virtual method called "feed"... | codefeedback |
Write a program that calculates the average and standard deviation of a given set of survey results. The program should then display the results in an HTML table.
Input:
- An array of survey results in percentage format. The array can have any number of elements.
Output:
- An HTML table that displays the survey resul... | codefeedback |
Construct a dictionary from the provided list of tuples such that the keys and values are switched. The tuples will contain strings and integers. The keys in the original tuples will have unique values. The dictionary should be sorted in ascending order based on the original values in the tuples. The keys in the dictio... | codefeedback |
Create two classes 'Circle' and 'Rectangle' in Java which print the circumference and area of their respective shapes.
1. The 'Circle' class should have the following attributes and methods:
- Attributes: radius (double)
- Methods:
- getRadius(): returns the radius of the circle
- setRadius(double rad... | codefeedback |
Create a dictionary such that each element in the list is a key and the respective value is its length. However, if the length of the element is an odd number, the value should be multiplied by 2 before being stored in the dictionary.
words = ['cat', 'dog', 'elephant']
Expected output: {'cat': 6, 'dog': 6, 'elephant'... | codefeedback |
Construct an SQL query to delete records from the "users" table that have a name of "John" or "David" and have a registration date earlier than January 1, 20 | codefeedback |
Create a method that parses the provided HTML and returns a list of all the <p> tags along with their attributes and content.
<html>
<p class="intro">This is a test.</p>
<a href="">link</a>
<p id="test">Another test.</p>
</html> | codefeedback |
Write a paint program that displays a 100x100 grid on the screen. The program should allow the user to paint individual cells of the grid by clicking on them. The grid should start with all cells colored white, and the user should be able to choose between at least 5 different colors to paint with. Additionally, the pr... | codefeedback |
Edit a given JSON string to set a specific value in it while ensuring that the age is greater than or equal to 18. The JSON string should also contain an additional key-value pair "country": "United States" under the "address" object.
JSON String: {
"name": "John Doe",
"age": 20,
"address": {
"street": "1 Main S... | codefeedback |
Write a code in C to print a given decimal number in binary using bitwise operations. | codefeedback |
Replace each character of a string with the next character in alphabetic order, taking into consideration uppercase and lowercase letters. | codefeedback |
Create a function in JavaScript to extract the words from a given sentence that contains a specific letter, while ignoring any words that start with a vowel. The function should also return the number of times the specific letter appears in the extracted words.
Sentence: The quick brown fox jumps over the lazy dog
Lett... | codefeedback |
Create a class named 'Shape' which has a method 'getArea' that takes in a length and width as parameters and returns the area of the shape. The length and width should both be positive integers. | codefeedback |
Create an array of length 1000 and set the values to the first 1000 prime numbers. | codefeedback |
Refactor the following code in C++ to incorporate dynamic memory allocation and sort the array in ascending order.
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter the size of the array: ";
cin >> n;
int* a = new int[n];
cout << "Enter " << n << " integers: ";
for... | codefeedback |
Generate code to remove duplicate characters from a string and return the resulting string sorted in reverse order.
string = "google" | codefeedback |
Create an HTML page with a text input box, a submit button, and a table to display the results. When the user clicks the submit button, validate the input to ensure it is a valid email address. If the input is valid, add a new row to the table with the email address as the first column and the current date and time as ... | codefeedback |
Create a C# class that stores student information such as name, age, classes, and grades. Implement methods for adding and removing classes, calculating the average grade, and displaying the student's information. Additionally, create a method that sorts the students in descending order based on their average grade. | codefeedback |
Generate a SQL query to update the existing row in the table "employee". Add a new constraint that only allows the update if the employee's department is "Sales". Set the salary to 5000 where the employee's id is 2. | codefeedback |
Implement a recursive binary search algorithm to find the index of a given target value in a sorted array. The algorithm should return -1 if the target value is not present in the array. Your implementation should have a time complexity of O(log n). | codefeedback |
Generate a program that finds the sum of all natural numbers from 0 to n, but with the following additional requirements:
1. The program should use a recursive function to calculate the sum.
2. The program should have a time complexity of O(n).
3. The program should not use any built-in sum() or range() functions.
4. ... | codefeedback |
Write a program that takes a binary number as input and calculates the sum of all the digits in the number. | codefeedback |
Create a MySQL query to select all customers who have purchased at least two items from a specific store in the last seven days. Additionally, the query should only include customers who have spent a total of more than $100 on their purchases at that store.
store_id = 12345 | codefeedback |
Design a function to take a string input and reverse the order of its words. However, the function should exclude any consecutive duplicate words in the reversed string.
string = "This is is a sentence" | codefeedback |
Design a function that takes in a positive integer greater than 1 and prints the multiplication table for that input number. The function should exclude all multiples of 3 from the table. | codefeedback |
Write an SQL query to calculate the sum of all prices of items purchased by customers, excluding any items with a price greater than $100.
#Explanation#
The original question was quite straightforward, as it only required calculating the sum of prices. To increase the difficulty, we added a condition to exclude items ... | codefeedback |
Generate a Java program to sort an array of n elements in ascending order using the merge sort algorithm. The program should have a time complexity of O(n log n) and should be able to handle large arrays of up to 10^6 elements efficiently. | codefeedback |
Implement a function which will take two strings as input and reverse their order while maintaining the same character at each index. The length of each string will be at most 100 characters. The function should return the reversed strings concatenated together with a hyphen in between. If the length of the strings are... | codefeedback |
Create a program to solve a math equation given in a string. The equation can contain addition, subtraction, multiplication, and division operations, as well as parentheses to group operations. The equation may also contain multiple operations of the same type consecutively (e.g., "3+2+1"). The equation should be evalu... | codefeedback |
Create an HTML page to display a heading, a table and a button.
headline = “List of Products”
table_headers = [“Name”, “Price”, “Quantity”]
In addition to the given requirements, modify the HTML page to include the following functionalities:
1. Sorting: Allow the user to sort the table data by clicking on the table h... | codefeedback |
Find the bug in the following C++ program and suggest a fix.
Write a function named "isSorted" that takes in an array of integers and its size as parameters. The function should return a boolean value indicating whether the array is sorted in ascending order or not.
Example usage:
int arr1[] = {1, 2, 3, 4, 5};
int ar... | codefeedback |
Suggest the most efficient and optimized way to store the given data structure in a MySQL database, considering that the database needs to handle millions of records efficiently. | codefeedback |
Using Java, create a program that takes a list of strings, and returns the longest one. However, you must implement a custom sorting algorithm to sort the strings in ascending order of their lengths before finding the longest one. You are not allowed to use any built-in sorting functions or libraries. The program shoul... | codefeedback |
Train a model to classify text into three categories, positive, negative, and neutral. Additionally, implement a data preprocessing step to remove stop words from the text before training the model. | codefeedback |
Create a program in JavaScript that will take a list of numbers and return the first index of the highest value. However, the program should not use any built-in array methods such as sort(), reduce(), or indexOf(). | codefeedback |
Use Node.js to create a program which will take an array of strings and remove any duplicate values. Additionally, the program should also ignore any duplicate values that have different capitalization. The program should also handle arrays with a size of up to 1 million strings efficiently. | codefeedback |
Use Django to create a basic website for a restaurant that includes user authentication, allowing users to create accounts and login to access personalized features. Additionally, implement a feature that allows users to make reservations for specific dates and times, with a maximum limit of 10 reservations per day. | codefeedback |
Create a program in Go that will take an array of integers and return the smallest number. Additionally, your program should handle arrays with a length of up to 10^6 and the integers in the array can range from -10^9 to 10^9. Your program should also efficiently handle duplicate numbers in the array without affecting ... | codefeedback |
Given a URL string, create a JavaScript function to extract the domain name. The URL can be of any length and can contain various subdomains and directories. The function should handle both HTTP and HTTPS URLs. | codefeedback |
Using Java, build a program that will convert a given number from one base to another. Your program should handle base conversion for numbers ranging from 1 to 10^6. The program should also handle negative numbers and display the converted number with appropriate sign. Additionally, your program should provide the opti... | codefeedback |
Suggest an algorithm in Python that will detect anomalies in a large dataset of time-series data. The algorithm should be able to handle datasets with millions of data points efficiently. The time complexity of the algorithm should be less than O(n^2), where n is the number of data points in the dataset. Additionally, ... | codefeedback |
Write a SQL query to find all records from the table 'products' with a price equal to 10, excluding any products that are out of stock. | codefeedback |
Count the number of parameters for the given function, with the additional constraint that the function should only accept a maximum of 5 parameters. Additionally, the function should not use any built-in functions or libraries to count the parameters. | codefeedback |
Parse the following text and remove all non-alphanumeric characters. Then, count the occurrences of each word in the text and display them in descending order of frequency.
Input: "Hello$#@, this is a te*x&t"
Output:
- "Hello" : 1
- "this" : 1
- "is" : 1
- "a" : 1
- "te" : 1
- "x" : 1
- "t" : 1 | codefeedback |
Change the given array to a singly linked list without using a loop and in reverse order.
array = [5, 4, 3, 2, 1] | codefeedback |
Create a program that prints the greatest common divisor between two numbers, where the numbers must be positive integers. Additionally, the program should check if the two numbers are relatively prime, and if they are not, it should output a message indicating that they are not relatively prime. The program should han... | codefeedback |
Explain how to use Binary Search in Python to find the first occurrence of a target element in a sorted array?
#Solution#
Binary Search is an efficient searching algorithm used to find a specific target element in a sorted array. Here's how you can implement it in Python to find the first occurrence of the target elem... | codefeedback |
Output the Fibonacci sequence up to 50, but you are not allowed to use any loops or recursion in your solution. | codefeedback |
Write a function that returns the length of the longest common substring between two strings, but with the following additional requirements:
1. The time complexity of the function should be O(n^2), where n is the length of the longer string.
2. The space complexity of the function should be O(1), meaning it should not... | codefeedback |
Complete the following function to output a reversed string, but you are not allowed to use any built-in string reversal functions or methods. | codefeedback |
Create a function in SQL to find the highest salary among employees from different departments. Additionally, the function should consider only those employees who have been working for at least 5 years and have a job level of at least 4. | codefeedback |
Given an integer n, write a program to print out the prime numbers up to n. Additionally, implement a function that checks whether a given number is a prime number or not. | codefeedback |
Create a function in JavaScript to sum two numbers, but without using the + operator or any other arithmetic operators. | codefeedback |
Given a 2D array of characters, replace each '0' entry with 'x' only if it is surrounded by at least two '1' entries horizontally or vertically. Otherwise, leave the entry unchanged. Return the modified 2D array.
Example:
Input:
[
['1', '0', '1'],
['0', '1', '0'],
['1', '0', '1'],
]
Output:
[
['1', '0', '1'],
[... | codefeedback |
Rewrite the program to get the same output, but this time the program should not use any loops. | codefeedback |
Increase the difficulty of the given programming test question by introducing a new requirement:
- Modify the given code to set the third parameter to 0 without using any conditional statements (e.g., if, else, switch) or arithmetic operators (e.g., +, -, *, /, %). | codefeedback |
Compose a program to reverse a list of numbers without using any built-in functions or methods. The program should only use a single loop and a constant amount of extra space. The time complexity should be O(n), where n is the length of the input list. | codefeedback |
Modify the code to check if the input string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward.
Requirements:
- The time complexity of the solution should be O(n), where n is the length of the input string.
- The space complexity of the s... | codefeedback |
Program a function to remove all prime numbers from an array | codefeedback |
Write a code to encode a given body of text into base64, but also ensure that the encoding is done in reverse order of the usual base64 encoding. For example, instead of encoding 'Hello World' as 'SGVsbG8gV29ybGQ=', you should encode it as 'QGQsYmGsbydibGk=ZG90dGVyL2J5dGVzOg=='. | codefeedback |
Write a code to decrypt a given cipher text using the Caesar cipher.
cipher_text = "dfwlrq"
Reference code (erroneous):
```python
def decrypt_caesar(cipher_text, key):
decrypted_text = ""
for char in cipher_text:
if char.isalpha():
if char.islower():
decrypted_text += chr(... | codefeedback |
Given a list of tuples representing a tree structure, where each tuple contains two elements: the value of a node and a list of its children, output the tree structure in Python. The output should include the parent-child relationship and indentation to indicate the level of each node.
For example, given the following... | codefeedback |
Write a JavaScript function that takes an array and counts the occurrence of each element in the array. The function should also sort the elements in descending order based on their occurrence count and return an array of objects with each object containing the element and its occurrence count. Additionally, the functi... | codefeedback |
Compile a function that checks if a number is a perfect square and a prime number. Output true if both conditions are met, false otherwise. | codefeedback |
Write a function that sorts an array of strings in ascending order based on the number of distinct characters in each string. If two or more strings have the same number of distinct characters, sort them lexicographically.
#Erroneous Code Reference#
Provide an erroneous code snippet that attempts to solve the problem ... | codefeedback |
Construct an SQL query to read the contents of a table called "users" and sort the results in descending order based on the "last_name" column. | codefeedback |
Explain how the Naive Bayes classifier works and provide a code implementation in Python. | codefeedback |
Output the longest consecutive string of non-repeating characters in a given string. | codefeedback |
Take an array of strings and return a new array containing only the strings with the longest length. If there are multiple strings with the longest length, return all of them in the new array. If the input array is empty, return an empty array. If the input array contains only empty strings, return an array with all th... | codefeedback |
Using Numpy, create an array of size 10 and fill it with unique random integer numbers between 0 and 9, without using any loops. | codefeedback |
Take an array of integers and return true if there is a triplet whose sum is equals to the given target. The triplet should consist of unique elements and the sum of any two elements in the triplet should not be equal to the target. Additionally, the function should return false if there are more than one valid triplet... | codefeedback |
Create a function that takes a matrix (MxN array) and returns a new matrix where each element is the sum of the corresponding element in the original matrix and its neighboring elements (top, bottom, left, right). | codefeedback |
Generate a 10 character random user password with at least one Upper Case letter, one lower case letter, one number, and one special character. Additionally, ensure that the password does not contain any repeated characters. | codefeedback |
Generate a 10 by 10 multiplication table. | codefeedback |
Create a web page with a login form that has 2 input fields.
Additionally, validate the input fields to ensure that the username field accepts only alphanumeric characters and the password field accepts a minimum of 8 characters, including at least one uppercase letter, one lowercase letter, and one special character.... | codefeedback |
Scrape the results of a web page and extract all the names and emails. However, the web page is dynamically generated using JavaScript and requires interaction with buttons and dropdown menus to load the content. | codefeedback |
Create a class called "Computer" with two attributes "name" and "model" and two methods "get_name" and "get_model". The "get_name" method should return the name of the computer and the "get_model" method should return the model of the computer.
However, the "get_name" method should only return the name if it is a stri... | codefeedback |
Implement a sorting algorithm which takes an array of integers as input and sorts it in ascending order. The sorting algorithm must use a time complexity of O(nlogn) and must not use any built-in sorting functions or libraries. The input array may contain duplicate values and the algorithm must handle them correctly. T... | codefeedback |
Given an array of numbers, find the maximum product of any three distinct numbers in the array. The array will have at least 6 numbers. You may not use sorting or nested loops to solve this problem.
arr = [2, 5, 6, 9, -2, -7, -1] | codefeedback |
Write a SQL query to find the top 5 most common first names from a given table of names, excluding any names that occur less than 100 times. | codefeedback |
Given an array of positive integers, find the longest subarray with the total sum equal to the given sum. The subarray must contain at least one odd integer and one even integer. Return the subarray itself.
arr = [2, 5, 1, 6, 3, 4], sum = 8 | codefeedback |
Create a SQL query to get the names of the customers who have placed orders more than 5 times and whose total order amount is greater than $1000. | codefeedback |
Write a Java program to remove n characters from a given string, starting from a specified position. The removed characters should be replaced with a specified character.
The program should have the following methods:
1. `removeCharacters(String str, int n, int pos, char replacementChar)`: This method takes in the or... | codefeedback |
Using the comment as a guide, insert a for loop in the following code to print out all odd numbers from 1 to 10, with a time complexity of O(n/2) and a space complexity of O(1).
# TODO: Insert a for loop here | codefeedback |
Calculate the total number of unique elements in this array, where each sub-array contains exactly two elements. Additionally, the elements in each sub-array are restricted to be positive integers greater than zero. | codefeedback |
Write a shell script to detect the internet speed, display it in the terminal, and log it to a file.
Requirements:
1. The script should measure both the download and upload speeds.
2. The script should display the speeds in a human-readable format, such as Mbps or Kbps.
3. The script should log the speeds to a file wi... | codefeedback |
Create a function to check if the two strings can be made equal by replacing the letters with asterisks and numbers in the same order. The numbers should correspond to the number of times each letter appears consecutively.
String s1 = "aaabbcc";
String s2 = "a*3b*2c*2"; | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.